GitHub – aoyan107/node-express-mysql-boilerplate: A boilerplate for any enterprise rest api or service with Node.js, Express and Sequelize ORM for mysql, postgresql or others.

Boilerplate for Node-Express with sequelize ORM

A boilerplate for any enterprise rest api or service with Node.js, Express and Sequelize ORM for mysql, postgresql or others.

By running this project you will get a production ready environment with all necessary supports for validation, unit testing, socket, redis and many more.

Manual Installation

Clone the repo:

git clone https://github.com/aoyan107/node-express-mysql-boilerplate

cd

node-express-mysql-boilerplate

Install the dependencies:

yarn install

Set the environment variables:

cp .env.example .env

#

open .env and modify the environment variables (if needed)

Features

  • ORM: Sequelize orm for object data modeling
  • Migration and Seed: DB migration and Seed using Sequelize-CLI
  • Authentication and authorization: using passport
  • Error handling: centralized error handling
  • Validation: request data validation using Joi
  • Logging: using winston
  • Testing: unittests using Mocha
  • Caching: Caching using Redis
  • Bidirectional Communication: using Scoket
  • Job scheduler: with Node-cron
  • Dependency management: with Yarn
  • Environment variables: using dotenv and cross-env
  • CORS: Cross-Origin Resource-Sharing enabled using cors
  • Docker support
  • Linting: with ESLint and Prettier

Commands

Running locally:

yarn dev

Running in production:

yarn start

Testing:

#

run all testsyarn

test

Environment Variables

The environment variables can be found and modified in the .env file. They come with these default values:

#

Server environmentNODE_ENV=development

#

Port numberPORT=5000

#

Db configurationDB_HOST=db-hostDB_USER=db-userDB_PASS=db-passDB_NAME=db-name

#

JWT secret keyJWT_SECRET=your-jwt-secret-key

#

Number of minutes after which an access token expiresJWT_ACCESS_EXPIRATION_MINUTES=5

#

Number of days after which a refresh token expiresJWT_REFRESH_EXPIRATION_DAYS=30

#

Log configLOG_FOLDER=logs/LOG_FILE=%DATE%-app-log.logLOG_LEVEL=error

#

RedisREDIS_HOST=redis-hostREDIS_PORT=6379REDIS_USE_PASSWORD=noREDIS_PASSWORD=your-password

Project Structure

specs\src\ |--config\         # Environment variables and configuration related things |--controllers\    # Route controllers (controller layer) |--dao\            # Data Access Object for models |--db\             # Migrations and Seed files |--models\         # Sequelize models (data layer) |--routes\         # Routes |--services\       # Business logic (service layer) |--helper\         # Helper classes and functions |--validations\    # Request data validation schemas |--app.js          # Express app |--cronJobs.js     # Job Scheduler |--index.js        # App entry point

License

MIT