- Install dependencies
npm i
-
Make sure you have the up to date env file
-
Run the project in dev mode
npm run dev
- If you were to run the project with a custom cpu number (default 1 cpu)
CPUNUM=numberofcpu npm run dev
- Example (1 cpu)
CPUNUM=1 npm run dev
We will use model:generate command. This command requires two options:
- name: the name of the model;
- attributes: the list of model attributes. Let's create a model named User.
npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
This will:
- Create a model file user in models folder;
- Create a migration file with name like XXXXXXXXXXXXXX-create-user.js in migrations folder.
npm run db:sync
npm run db:sync:undo
npx sequelize-cli seed:generate --name demo-user
This command will create a seed file in seeders folder. File name will look something like XXXXXXXXXXXXXX-demo-user.js. It follows the same up / down semantics as the migration files.
Now we should edit this file to insert demo user to User table.
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [
{
firstName: 'John',
lastName: 'Doe',
email: 'example@example.com',
createdAt: new Date(),
updatedAt: new Date(),
},
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
},
};
npm run db:seed
npm run db:seed:undo
Lets look at some exmaples 🔥
Note: To run the preceding commands, Node.js and npm must be installed.
-
Clustering
in Node.js - Testing API speed with
loadtest
- Server with
Express.js
- Database schema and models using
Sequelize ORM
. - User authentication with
JWT
. -
StandardJs
for coding standards and styling. - Request validation using
Express-validator
. -
Morgan and Winston
for server side logging. -
Swagger
for API documentation.