Nuxt module to integrate sequelize and model at server api
- Integrate with sequelize model
- Add controller support on server handler
- Authentication using token header
1.Install the module to your Nuxt application with one command:
npx nuxi@latest module add @mhmdzaien/nuxt-sequelize
2.Add @mhmdzaien/nuxt-sequelize, models path and nitro support decorator in nuxt.config.ts
export default defineNuxtConfig({
modules: [@mhmdzaien/nuxt-sequelize],
nitro: {
esbuild: {
options: {
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
},
},
},
},
},
nuxtSequelize: {
modelPath: './server/models',
},
})
3.Create index.js inside 'modelPath' that contain loader to model
export function initModels(sequelize: Sequelize) {
User.initModel(sequelize)
}
4.Create .env file contain database configuration
DB_NAME=
DB_USER=root
DB_PASSWORD=
DB_HOST=localhost
DB_DRIVER=
DB_DRIVER is one of sequelize supported dialect
That's it! You can now use My Module in your Nuxt app ✨
- handler : Function(event) => callback handler with event parameter
- authorizeRequest : "*" | Array => if set handler check authentication in token header accepted role number
Local development
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release