Skip to content

umakantv/node-express-sequelize-boilerplate

Repository files navigation

Node, express, Postgres-Sequelize boiler-plate

Dependencies

  • "dotenv": "^8.2.0"
  • "express": "^4.17.1"
  • "pg": "^8.0.3"
  • "pg-hstore": "^2.3.3"
  • "sequelize": "^5.21.7"
  • "sequelize-cli": "^5.5.1"

Pre-run tasks

Tutorial

  1. npm i
  2. Delete database folder and run sequelize init to initialize .sequelize file.
  3. Modify the database/config/config.js file like so:
"development": {
  "url": process.env.DEV_DB_URL,
  "dialect": "postgres"
}

Note: Modify other envs as well.

  1. Modify models/index.js file like so.
let sequelize;
if (config.url) {
  sequelize = new Sequelize(config.url);
} else {
  sequelize = new Sequelize(config.database, config.username, config.password, config);
}
  1. Create models and migrations using command:
    sequelize model:generate --name <model_name> --attributes <attributes>
    E.g.: sequelize model:generate --name User --attributes name:string,email:string
  2. Modify the respective model files. Add their associations.
  3. Edit/Create the .env file
  4. Run the command: sequelize db:migrate to create tables in the database.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published