npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

create-gs-express-ms

v1.0.13

Published

πŸš€ Production-ready Node.js Express microservices boilerplate with MongoDB, Redis, RabbitMQ, and complete authentication

Downloads

1,455

Readme

Production-Ready Node.js Microservices Boilerplate

License: MIT Node.js Version

A complete, production-ready Node.js microservices architecture following 2025 best practices with advanced security, performance optimizations, and comprehensive DevOps support.

πŸ—οΈ Architecture

This boilerplate implements a microservices architecture with the following services:

  • API Gateway (Port 3000) - Single entry point, routing, rate limiting
  • Auth Service (Port 3001) - Authentication, authorization, JWT, OAuth
  • User Service (Port 3002) - User management, CRUD operations
  • Notification Service (Port 3003) - Email (SMTP) & Push notifications (FCM)

Infrastructure

  • MongoDB - Primary database
  • Redis - Caching, sessions, rate limiting
  • RabbitMQ/BullMQ - Message queue for background jobs

✨ Features

πŸ” Security

  • βœ… JWT Access + Refresh tokens with secure HTTP-only cookies
  • βœ… Role-Based Access Control (RBAC)
  • βœ… API Key authentication for internal services
  • βœ… Advanced security middlewares (helmet, xss-clean, hpp, cors)
  • βœ… Request sanitization (NoSQL injection, XSS)
  • βœ… Rate limiting with Redis
  • βœ… CSRF token support
  • βœ… Account locking after failed login attempts

πŸš€ Performance

  • βœ… Redis caching
  • βœ… Response compression
  • βœ… PM2 cluster mode support
  • βœ… Database query optimization
  • βœ… Connection pooling

πŸ”§ Development

  • βœ… Clean MVC architecture
  • βœ… Comprehensive error handling
  • βœ… Request validation with Joi
  • βœ… Logging with Winston + Morgan
  • βœ… Hot reload with Nodemon
  • βœ… ESLint + Prettier
  • βœ… Environment-based configuration

πŸ“¬ Communication

  • βœ… Email service with Nodemailer
  • βœ… Email templates (welcome, verification, password reset)
  • βœ… Firebase Cloud Messaging (FCM) for push notifications
  • βœ… BullMQ for background job processing
  • βœ… Event-driven architecture

πŸ§ͺ Testing

  • βœ… Jest + Supertest setup
  • βœ… Unit and integration tests
  • βœ… Test coverage reports

πŸ“š Documentation

  • βœ… Swagger/OpenAPI documentation
  • βœ… Comprehensive README
  • βœ… API documentation for all routes

🐳 DevOps

  • βœ… Docker + Docker Compose
  • βœ… Multi-stage Dockerfile
  • βœ… GitHub Actions CI/CD
  • βœ… PM2 ecosystem configuration
  • βœ… Health check endpoints

πŸ“‹ Prerequisites

  • Node.js >= 18.0.0
  • MongoDB >= 6.0
  • Redis >= 7.0
  • Docker & Docker Compose (optional)
  • npm or yarn

πŸš€ Quick Start

Using Docker (Recommended)

# Clone the repository
git clone <repository-url>
cd nodejs-microservices-boilerplate

# Copy environment variables
cp auth-service/.env.example auth-service/.env
cp user-service/.env.example user-service/.env
cp notification-service/.env.example notification-service/.env
cp api-gateway/.env.example api-gateway/.env

# Start all services with Docker Compose
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Using Makefile

# Install dependencies for all services
make install

# Start all services in development mode
make dev

# Run tests for all services
make test

# Lint all services
make lint

# Format code
make format

# Clean node_modules and logs
make clean

Manual Setup

# Install dependencies for each service
cd shared && npm install
cd ../auth-service && npm install
cd ../user-service && npm install
cd ../notification-service && npm install
cd ../api-gateway && npm install

# Start MongoDB
mongod

# Start Redis
redis-server

# Start each service (in separate terminals)
cd auth-service && npm run dev
cd user-service && npm run dev
cd notification-service && npm run dev
cd api-gateway && npm run dev

πŸ”§ Configuration

Environment Variables

Each service has its own .env file. Copy the .env.example file and update the values:

# Auth Service
cd auth-service
cp .env.example .env
# Edit .env with your configuration

# Repeat for other services

Key Configuration

  • JWT_SECRET: Change to a strong random string
  • API_KEY_*: Generate unique API keys for each service
  • MONGODB_URI: Your MongoDB connection string
  • REDIS_HOST/PORT: Your Redis configuration
  • SMTP_*: Your email provider credentials
  • GOOGLE_CLIENT_ID/SECRET: For Google OAuth
  • APPLE_*: For Apple OAuth

πŸ“– API Documentation

Once the services are running, access the Swagger documentation:

  • API Gateway: http://localhost:3000/api-docs
  • Auth Service: http://localhost:3001/api-docs
  • User Service: http://localhost:3002/api-docs
  • Notification Service: http://localhost:3003/api-docs

πŸ”‘ Authentication Flow

Register

POST /api/auth/register
{
  "name": "John Doe",
  "email": "[email protected]",
  "password": "Password123"
}

Login

POST /api/auth/login
{
  "email": "[email protected]",
  "password": "Password123"
}

Refresh Token

POST /api/auth/refresh-tokens
{
  "refreshToken": "your-refresh-token"
}

Protected Routes

GET /api/auth/me
Headers: {
  "Authorization": "Bearer your-access-token"
}

πŸ§ͺ Testing

# Run tests for all services
make test

# Run tests for a specific service
cd auth-service && npm test

# Run tests with coverage
npm test -- --coverage

# Run tests in watch mode
npm run test:watch

πŸ“¦ Project Structure

nodejs-microservices-boilerplate/
β”œβ”€β”€ api-gateway/          # API Gateway service
β”œβ”€β”€ auth-service/         # Authentication service
β”œβ”€β”€ user-service/         # User management service
β”œβ”€β”€ notification-service/ # Notification service
β”œβ”€β”€ shared/              # Shared utilities and middleware
β”œβ”€β”€ docker-compose.yml   # Docker Compose configuration
β”œβ”€β”€ Makefile            # Common commands
└── README.md           # This file

🐳 Docker Commands

# Build all services
docker-compose build

# Start services
docker-compose up -d

# View logs
docker-compose logs -f [service-name]

# Stop services
docker-compose down

# Remove volumes
docker-compose down -v

# Rebuild and restart
docker-compose up -d --build

πŸ”„ PM2 Cluster Mode

# Start with PM2
pm2 start ecosystem.config.js

# Monitor
pm2 monit

# View logs
pm2 logs

# Restart
pm2 restart all

# Stop
pm2 stop all

πŸ“Š Monitoring & Logging

  • Logs are stored in logs/ directory for each service
  • Winston logger with daily rotating files
  • Morgan for HTTP request logging
  • PM2 monitoring dashboard

πŸ”’ Security Checklist

  • [x] Environment variables properly configured
  • [x] Strong JWT secret
  • [x] Unique API keys for each service
  • [x] HTTPS enabled in production
  • [x] CORS properly configured
  • [x] Rate limiting enabled
  • [x] Input validation on all endpoints
  • [x] SQL/NoSQL injection protection
  • [x] XSS protection
  • [x] CSRF protection
  • [x] Secure HTTP headers (helmet)
  • [x] Password hashing with bcrypt
  • [x] Account lockout mechanism

πŸš€ Deployment

Production Checklist

  1. Update all .env files with production values
  2. Set NODE_ENV=production
  3. Use strong secrets and API keys
  4. Enable HTTPS
  5. Configure proper CORS origins
  6. Set up database backups
  7. Configure monitoring and alerting
  8. Review security settings
  9. Enable PM2 cluster mode
  10. Set up CI/CD pipeline

GitHub Actions

The repository includes a GitHub Actions workflow for CI/CD:

  • Runs tests on push/PR
  • Lints code
  • Builds Docker images
  • Deploys to production (configure as needed)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT License.

πŸ‘€ Author

Gagan Saddal

πŸ™ Acknowledgments

  • Express.js team
  • Mongoose team
  • All open-source contributors

πŸ“ž Support

For issues and questions:

  • Create an issue on GitHub
  • Check the documentation
  • Review existing issues

Made with ❀️ for the Node.js community