How to create and structure NodeJS Project with ORM

Code to create NodeJS API’s with Sequelize as ORM:

1.       npm init à Create a package.json file

2.       npm install express à For framework

3.       npm install sequelize & npm install sequelize-cli à ORM

4.       npx sequelize-cli init à To create the MVC architecture in the project (create the folders for that)

5.       npx sequelize-cli model:generate –name nameOfModel –attributes columnName:DataType à To create a model for the table.

6.       npx sequelize-cli db:migrate à Migrate the created table to the respective DB

 

Seeder:

1.       npx sequelize-cli sed:generate –name categories-seeder à To create seeder file for a particular table.

2.       npx sequelize-cli db:seed:undo à Undo the recently seeded Data from the DB

3.       npx sequelize-cli db:seed:all à Undo the all seeded Data from the DB

Did you find this article useful?