🚀 Node.js Boilerplate with Express with auth, database config , logging, REST API template etc

This boilerplate includes the setup for a Node.js application using Express, MySQL with Sequelize ORM, and Winston for logging.

📋 Prerequisites

- Node.js: >= v18.16.1
- Framework: Express
- Database: MySQL
- ORM: Sequelize
- Logger: Winston



📦 Installation

  1. Copy the example environment file:

    cp .envexample .env
  2. Install dependencies:

    npm install
  3. For development:

    npm run watch
  4. For production:

    npm run build



📖 Development Documentation


⚙️ Port Configuration

You can configure the port on which your application runs. Check the .env file:

APP_PORT=5000

🗄️ Connect Your Database

Update the .env file according to your database configuration:

# DB CONFIGURATION
DB_CONNECTION=mysql
DB_NAME=sts
DB_USERNAME=root
DB_PASSWORD=secret
DB_HOST=localhost
DB_PORT=33060



🔄 Migrations and Models

Generate Model with Migration

npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string

Generate a migration:

npx sequelize-cli migration:generate --name migration-skeleton

Run Migrations

npx sequelize-cli db:migrate --to XXXXXXXXXXXXXX-create-posts.js

Run all migrations:

npx sequelize-cli db:migrate

Rollback the last migration:

npx sequelize-cli db:migrate:undo

Rollback all migrations:

npx sequelize-cli db:migrate:undo:all

Rollback to a specific migration:

npx sequelize-cli db:migrate:undo:all --to XXXXXXXXXXXXXX-create-posts.js



Seed Operations 🌱

Generate a seed:

npx sequelize-cli seed:generate --name demo-user

Run all seeds:

npx sequelize-cli db:seed:all

Undo the last seed:

npx sequelize-cli db:seed:undo

Undo all seeds:

npx sequelize-cli db:seed:undo:all

Undo a specific seed:

npx sequelize-cli db:seed:undo --seed name-of-seed-as-in-data



Logging 📜

You can modify your log configuration by updating the .env file:

LOG_LEVEL='info'
LOG_STORAGE_PATH='src/storage/logs'

Log levels:

error: 0
warn: 1
info: 2
http: 3
verbose: 4
debug: 5
silly: 6

Example of writing logs in your application:

logger.info('userProfile', 200, 'User profile fetched successfully', { user: req.user });
logger.warn('This is a warning message');
logger.error('This is an error message');
logger.debug('This is a debug message');



Download API Collection

https://www.postman.com/warped-space-453686/workspace/open-source/collection/12535469-0d506ab2-9014-49b0-b587-c40560bddf55?action=share&creator=12535469