Skip to content

djibril6/restapi-nodejs-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Rest API boilerplate

Coverage Status Build Status

Node.js, express, Typescript and mongoDB project boilerplate

Installation with create-nodejs-boilerplate

npx create-nodejs-boilerplate <project-name> --template RestAPI

Manual installation

Clone the repository:

git clone https://github.com/djibril6/restapi-nodejs-boilerplate.git
# Then
npx rimraf ./.git

Then create a new .env file in the project root directory and copy the .env.exemple file content (this step not necessary in the project in installed with create-node-js-boilerplate).

Install the dependencies for the project:

npm install

Environnement variables

Edit the .env file by adding the corrects value for each field.

Features used in this project

  • NoSQL database: MongoDB object data modeling using Mongoose
  • Email service: Email API service Sendgrid
  • Validation: request data validation using Joi
  • Logging: using winston and morgan
  • Testing: unit and integration tests using Jest
  • Error handling: centralized error handling mechanism
  • API documentation: with swagger-jsdoc and swagger-ui-express
  • Process management: advanced production process management using PM2
  • Security: set security HTTP headers using helmet
  • Santizing: sanitize request data against xss and query injection
  • CORS: Cross-Origin Resource-Sharing enabled using cors
  • Compression: gzip compression with compression
  • CI: continuous integration with Travis CI
  • Docker support
  • Code coverage: using coveralls
  • Code quality: with Codacy
  • Git hooks: with husky and lint-staged
  • Linting: with ESLint and Prettier
  • Editor config: consistent editor configuration using EditorConfig

Project Structure

src\
 |--config\         # Environment variables and global configurations 
 |--controllers\    # All Route controllers
 |--middlewares\    # All Custom express middlewares
 |--models\         # All Mongoose models
 |--routes\         # RestFull Api Routes 
 |--services\       # All database query and services(Business logic)
 |--types\          # All TypeScript shared interfaces and enums
 |--utils\          # Utility classes and functions
 |--validations\    # All data validation logics
 |--server.ts       # Express app
 |--index.ts        # App entry point
test\
 |--integration\    # integration test files
 |--utils\          # utilty functions for test

API Documentation

In development mode and go to http://localhost:{PORT}/v1/docs in your browser.

Authentication

We are using an access and refresh token system.

Logging

Logging should be done with the logger module (do not use console.log()) located in src/config/logger.js, according to the following severity levels:

import { config, logger } from '<path to src>/config';

logger.error('message'); // level 0
logger.warn('message'); // level 1
logger.info('message'); // level 2
logger.http('message'); // level 3
logger.verbose('message'); // level 4
logger.debug('message'); // level 5

Inspirations

About

Modular Node.js with typescript boilerplate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages