/express-mongoose-boilerplate

A boilerplate for building production-ready RESTful APIs using Node.js, Express, Mongoose, Docker and Redis

Primary LanguageJavaScriptMIT LicenseMIT

Node.js (Express) and MongoDB (Mongoose) Boilerplate

Showcase Image

This is a boilerplate project that provides a secure starting point for building web applications with Node.js (Express.js) and MongoDB (Mongoose). It also includes a Docker container for easy deployment and scalability, as well as Redis for rate limiting.

Features

  • NoSQL database: MongoDB object data modeling using Mongoose
  • Security: set security HTTP headers using helmet
  • Santizing: sanitize request data against xss, query injections and HTTP parameter pollution using xss-clean, express-mongo-sanitize & hpp
  • Rate Limiting: prevent small DDOS and Brute-Force Attacks using rate-limiter-flexible
  • CORS: Cross-Origin Resource-Sharing enabled using cors
  • Error handling: centralized and async error handling mechanism with a custom error class
  • Compression: gzip compression with compression
  • Logging: using morgan
  • Docker support: for easy deployment and scalability
  • Best Practices: Async catch handler, Directory Structure, Validation

Getting Started

Prerequisites

  • Node.js (version 12 or higher)
  • MongoDB Database
  • Docker

Installation

  1. Clone the repository to your local machine:
git clone https://github.com/0xBitBuster/express-mongoose-boilerplate.git
  1. Set environment variables in docker-compose.dev.yaml and docker-compose.yaml

Usage

To start the server, run:

docker-compose up [-f docker-compose.dev.yaml]

By default, the server runs on http://localhost:80

Contributing

Contributions are welcome! If you have a feature request or bug report, please open an issue. If you want to contribute code, please fork the repository and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.