Node.js, express, Typescript and mongoDB project boilerplate
npx create-nodejs-boilerplate <project-name> --template RestAPI
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
Edit the .env
file by adding the corrects value for each field.
- 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
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
In development mode and go to http://localhost:{PORT}/v1/docs
in your browser.
We are using an access and refresh token system.
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
- Inspired from hagopj13/node-express-boilerplate project.
- The javascript hagopj13/node-express-boilerplate project.