A production ready boilerplate/starter project for quickly building RESTful APIs using Node.js, Express, and Mongoose. Authentication using JWT, request validation, API documentation, pagination, etc. For more details, check the features list below.
You may need to make the .env
file and set environment variables in it.
Refer .env.example
Run the following command.
npm install
or
yarn install
- Features
- Commands
- Environment Variables
- Project Structure
- Error Handling
- Validation
- Authentication
- Logging
- Custom Mongoose Plugins
- Linting
- Contributing
- Database: MongoDB object data modeling using Mongoose
- Authentication and authorization: using jwt
- Validation: request data validation using Joi
- Logging: using winston and morgan
- Error handling: error handling mechanism is centralized
- Process management: advanced production process management using PM2
- Dependency management: with NPM
- Environment variables: using dotenv and cross-env
- Security: set security HTTP headers using helmet
- Sanitizing: sanitize request data against xss and query injection
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Compression: gzip compression with compression
- Git hooks: with husky and lint-staged
- Linting: with ESLint
Running locally:
npm run dev
Running in production:
npm start
Testing:
# run all tests
npm run test
# run all tests in watch mode
npm run test:watch
# run test coverage
npm run coverage
Linting:
# run ESLint
npm run lint
# fix ESLint errors
npm run lint:fix
## Linting
Linting is done using [ESLint](https://eslint.org/).
To modify the ESLint configuration, update the `.eslintrc.json` file.
To prevent a certain file or directory from being linted, add it to `.eslintignore`.