Skip to content

Shaunmak1214/cluster-node-auth-sql-boilerplate

Repository files navigation

Inva UI
Clustering in NodeJs · Auth · Mysql

JavaScript Style Guide forthebadge


Guides

Run the project

  1. Install dependencies
npm i
  1. Make sure you have the up to date env file

  2. 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

Create New Model/Migration

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.

Running the migtrations (syncing it with the database)

npm run db:sync

Undoing migrations

npm run db:sync:undo

Creating Seeders

npx sequelize-cli seed:generate --name demo-user
Populating the seeders

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, {});
  },
};

Running the seeds

npm run db:seed

Undoing the seeders

npm run db:seed:undo

Clustering Implemented

Lets look at some exmaples 🔥

Note: To run the preceding commands, Node.js and npm must be installed.

Boilerplate includes

  • 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.

License

MIT. Copyright (c) Shaun Mak.

About

A clustering based node-js boilerplate. Performance MAX 😍

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •