/typescript-node-sequelize-boilerplate

This is a boilerplate for node typescript and sequelize

Primary LanguageTypeScript

Typescript-Node-Sequelize-Boilerplate

A boilerplate/starter project for quickly building RESTful APIs using Node.js,Typescript, Express, and Sequelize.

  • Node
  • Typescript
  • Express
  • Sequelize (Oracle, Postgres, MySQL, MariaDB, SQLite and SQL Server etc.)

Table of Contents

Quick start

create boillerplate with single command

 npx  @nabadeep25/create-ts-node-app myapp

Manual Installation

steps:

Clone the repo:

git clone --depth 1 https://github.com/nabadeep25/typescript-node-sequelize-boilerplate.git  foldername

cd folder name
npx rimraf ./.git

Install the dependencies:

npm install

Set the environment variables:

cp .env.example .env

Getting started

npm install

npm run build-ts

npm start

For development

npm install

npm run dev

Sample .ENV

DB_HOST=localhost
DB_NAME=name
DB_PASSWORD=password
DB_PORT=3306
DB_TYPE=postgres
DB_USER=username
PORT=5000



TOKEN_EXPIRY_HOUR=168
SECRET=askjfghhwifuhgw

EMAIL_SERVICE=gmail
EMAIL_USER=you@email.com
EMAIL_PASS=fzobeitqjcxklenm
EMAIL_FROM=admin@email.com

OTP_EXPIRY_MIN=10
OTP_SECRET=shgdbnbgw

Commands

# run in development
npm run dev

# run in production
npm run start

#  lint files
npm run lint

#  format files
npm run format

Project Structure

dist\               # js files
src\
 |--config\         # Environment variables and configuration related things
 |--controllers\    # Route controllers 
 |--helpers\        # Helper function files
 |--middlewares\    # Custom express middlewares
 |--model\          # Sequelize models 
 |--routes\         # Routes
 |--services\       # Service 
 |--utils\          # Utility classes and functions
 |--validations\    # Request data validation schemas
 |--app.ts\         # Express app
 |--server.ts\      # App entry point

Changing Database

step 1

# Change the value of  DB_TYPE  in .env file to one of the follwing
DB_TYPE=postgres 
DB_TYPE=mysql 
DB_TYPE=sqlite 
DB_TYPE=mariadb 
DB_TYPE=mssql 
DB_TYPE=db2 
DB_TYPE=oracle 

step 2

# Install one of the related packge:
 npm install --save pg pg-hstore # for Postgres
 npm install --save mysql2 # for Mysql
 npm install --save mariadb # for Mariadb
 npm install --save sqlite3 # for Sqlite
 npm install --save tedious # for Microsoft SQL Server (mssql)
 npm install --save oracledb # for Oracle 

for more details please refer Sequelize

API Documentation

To view the list of available APIs and their specifications, run the server and go to http://localhost:5000/api/v1/docs in your browser. This documentation page is automatically generated using the swagger definitions written as comments in the route files.

API Endpoints

List of available routes:

General routes:
GET api/ - get server status
PATCH api/sync - Sync model with database

Auth routes:
POST api/v1/auth/register - register
POST api/v1/auth/login - login
POST api/v1/auth/forgot-password - send reset password email
POST api/v1/auth/reset-password - reset password

User routes:
GET api/v1/user - get user info
PATCH api/v1/user - update user

Inspirations