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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nest-boiler

v1.0.3

Published

CLI tool to generate production-ready NestJS boilerplate with database, Redis, worker, WebSocket, and Docker support

Downloads

418

Readme

NestJS Boilerplate Generator CLI

npm version License: MIT Node.js Version

🚀 CLI tool to generate production-ready NestJS boilerplate projects with complete database, Redis, Worker, WebSocket, and Docker support.

✨ Features

  • 🗄️ Database Support: MySQL, PostgreSQL, MongoDB, MongoDB Replica Set
    • TypeORM for SQL databases with migration support
    • Mongoose for MongoDB
    • Data Source configuration
    • Base Entity classes (BaseTimeEntity, BaseIncrementEntity, BaseUuidEntity)
  • 🔴 Redis Configuration: Integrated Redis cache with cache-manager
  • ⚙️ Worker Queue: Bull Queue with separate bootstrap, Redis global config
  • 🔌 WebSocket: Socket.IO gateway with separate bootstrap
  • 🐳 Docker Support: Dockerfile + docker-compose.yml with profiles
    • Multi-stage builds (builder, production, development)
    • Database admin tools (pgAdmin, phpMyAdmin, Mongo Express)
    • Health checks for all services
    • Production-ready configuration
  • Validation: class-validator and class-transformer
  • 📝 Logging: Winston logger with daily rotation and separate log files
  • 📚 API Documentation: Swagger/OpenAPI integration
  • 🔄 TypeScript: Full TypeScript support with proper types
  • 🎨 Code Quality: ESLint, Prettier pre-configured
  • 🛡️ Error Handling: Global exception filters and custom exceptions
  • 🔍 Interceptors: Request logging, response transformation

📦 Installation

Global installation (Recommended)

npm install -g nestjs-boilerplate-generator

Using npx (No installation required)

npx nestjs-boilerplate-generator new my-project

Install from source

git clone https://github.com/yourusername/nestjs-boilerplate-generator.git
cd nestjs-boilerplate-generator
npm install
npm link

🚀 Usage

Create a new project

nestjs-gen new my-project

or if not installed globally:

node bin/cli.js new my-project

Project generation process

The CLI will ask you the following questions:

  1. Choose database:

    • MySQL
    • PostgreSQL
    • MongoDB
    • MongoDB Replica Set
    • None
  2. Add Redis config? (Yes/No)

  3. Add Worker (Bull Queue)? (Yes/No)

  4. Add WebSocket? (Yes/No)

  5. Add Docker (Dockerfile + docker-compose.yml)? (Yes/No)

After creating the project

cd my-project
npm install
npm run start:dev

📁 Generated project structure

my-project/
├── src/
│   ├── common/
│   │   ├── config/
│   │   │   ├── database.config.ts    # Database config
│   │   │   ├── redis.config.ts       # Redis config
│   │   │   └── logger.config.ts      # Winston logger config
│   │   ├── constants/                # Application constants
│   │   ├── decorators/               # Custom decorators
│   │   ├── entities/
│   │   │   └── base.entity.ts        # Base entities (SQL only)
│   │   ├── enums/                    # Enums
│   │   ├── exceptions/               # Custom exceptions
│   │   ├── filters/                  # Exception filters
│   │   ├── interceptors/             # Request/Response interceptors
│   │   ├── logger/                   # Logger utilities
│   │   └── response/                 # Response DTOs
│   ├── migrations/                   # TypeORM migrations (SQL only)
│   ├── websocket/                    # WebSocket module (if selected)
│   │   ├── websocket.module.ts
│   │   └── websocket.gateway.ts
│   ├── worker/                       # Worker module (if selected)
│   │   └── worker.module.ts
│   ├── app.controller.ts
│   ├── app.service.ts
│   ├── app.module.ts                 # Main app module
│   ├── bootstrap.websocket.ts        # WebSocket bootstrap (if selected)
│   ├── bootstrap.worker.ts           # Worker bootstrap (if selected)
│   ├── data-source.ts                # TypeORM data source (SQL only)
│   └── main.ts                       # Main API bootstrap
├── logs/                             # Winston logs (auto-created)
│   ├── api/                          # API logs
│   ├── socket/                       # Socket logs
│   └── worker/                       # Worker logs
├── Dockerfile                        # Multi-stage Dockerfile (if selected)
├── docker-compose.yml                # Docker Compose config (if selected)
├── .dockerignore                     # Docker ignore file (if selected)
├── DOCKER_README.md                  # Docker documentation (if selected)
├── WORKER_README.md                  # Worker documentation (if selected)
├── .env
├── eslint.config.mjs
├── .gitignore
├── .prettierrc
├── nest-cli.json
├── package.json
├── tsconfig.json
├── tsconfig.build.json
└── README.md

🔧 Configuration

All configurations are stored in the .env file:

MySQL/PostgreSQL

DB_HOST=localhost
DB_PORT=3306  # or 5432 for PostgreSQL
DB_USERNAME=root
DB_PASSWORD=
DB_DATABASE=nestjs

MongoDB

MONGODB_URI=mongodb://localhost:27017/nestjs
MONGODB_REPLICA_SET=rs0  # If using Replica Set

Redis

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0

Docker (When Docker is selected)

Environment variables will be automatically configured for Docker:

  • Database hosts changed to service names (postgres, mysql, mongo, redis)
  • Passwords set to default your_secure_password (should be changed)
  • Admin tool credentials added automatically

Example with PostgreSQL + Docker:

# PostgreSQL Configuration (Docker)
DB_HOST=postgres
DB_PORT=5432
DB_USERNAME=nestjs
DB_PASSWORD=your_secure_password
DB_DATABASE=nestjs

# PostgreSQL Docker Configuration
POSTGRES_USER=nestjs
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=nestjs

# pgAdmin
[email protected]
PGADMIN_DEFAULT_PASSWORD=admin

📝 Scripts

The generated project will have these scripts:

Main API Scripts

npm run start          # Start the application
npm run start:dev      # Start in development mode with watch mode
npm run start:prod     # Start in production mode
npm run build          # Build project
npm run test           # Run unit tests
npm run test:e2e       # Run e2e tests
npm run lint           # Lint code
npm run format         # Format code with Prettier

WebSocket Scripts (Only when WebSocket is selected)

WebSocket runs on a separate server (port 3001):

npm run start:socket       # Start WebSocket server
npm run start:socket:dev   # Start WebSocket in development mode
npm run start:socket:prod  # Start WebSocket in production mode

Worker Scripts (Only when Worker is selected)

Worker runs in background (does not expose HTTP port):

npm run start:worker       # Start Worker process
npm run start:worker:dev   # Start Worker in development mode
npm run start:worker:prod  # Start Worker in production mode

Docker Scripts (Only when Docker is selected)

Docker Compose with profiles for development and production:

# Development stack (with database admin tools)
docker-compose --profile dev up -d

# Production stack
docker-compose --profile prod up -d

# Start specific services
docker-compose up postgres redis -d

# Stop all services
docker-compose down

# View logs
docker-compose logs -f

# Rebuild images
docker-compose build --no-cache

Migration Scripts (Only for SQL databases)

If you select MySQL or PostgreSQL, the following scripts will be added:

npm run migration:generate   # Generate migration from entities
npm run migration:run        # Run migrations
npm run migration:revert     # Revert the most recent migration

🔍 Feature Details

Database Integration

  • MySQL/PostgreSQL:
    • Uses TypeORM with auto configuration
    • Data Source configuration for migrations
    • Automatic migration scripts
    • Type-safe with TypeScript
  • MongoDB:
    • Uses Mongoose with connection string support
    • Supports Replica Set configuration

Redis

  • Integrated with @nestjs/cache-manager
  • Redis client version 4.6.0
  • Global cache module
  • Type-safe with @types/cache-manager
  • Easy to use in any service

Worker (Bull Queue)

  • Runs separately: Separate bootstrap (bootstrap.worker.ts)
  • Does not expose HTTP: Only processes jobs, no HTTP endpoint
  • Redis Global: Redis config pre-configured for all queues
  • Winston Logger: Integrated logging with LogModule.WORKER
  • Type-safe with @types/bull
  • Ready for background job processing
  • Can create multiple queues and processors
  • Automatic retry and failure handling
  • Job progress tracking

WebSocket

  • Runs separately: Separate bootstrap (bootstrap.websocket.ts)
  • Winston Logger: Integrated logging with LogModule.SOCKET
  • Socket.IO gateway version 4.7.2
  • CORS enabled
  • Event-driven architecture
  • Connection/Disconnection handling
  • Real-time bidirectional communication

Validation & Transformation

  • class-validator: Validate DTOs and request data
  • class-transformer: Transform plain objects to class instances
  • Auto validation with NestJS pipes

📦 Installed Dependencies

Core Dependencies (Always included)

  • @nestjs/common, @nestjs/core, @nestjs/platform-express
  • @nestjs/config - Configuration management
  • reflect-metadata, rxjs
  • class-validator, class-transformer - Validation & transformation

Database Dependencies (Optional)

MySQL:

  • @nestjs/typeorm, typeorm, mysql2
  • dotenv - Environment variables

PostgreSQL:

  • @nestjs/typeorm, typeorm, pg
  • dotenv - Environment variables

MongoDB:

  • @nestjs/mongoose, mongoose

Redis & Worker Dependencies (Optional)

  • @nestjs/cache-manager, cache-manager, cache-manager-redis-store
  • redis - Redis client
  • @nestjs/bull, bull - Queue management
  • @types/cache-manager, @types/bull - TypeScript types

WebSocket Dependencies (Optional)

  • @nestjs/websockets, @nestjs/platform-socket.io
  • socket.io - WebSocket library

Development Dependencies

  • @nestjs/cli, @nestjs/schematics, @nestjs/testing
  • typescript, ts-node, ts-loader
  • eslint, prettier - Code quality
  • jest, ts-jest, supertest - Testing

🤝 Contributing

Contributions, issues, and feature requests are welcome!

📄 License

MIT

👤 Author

Your Name


Made with ❤️ using NestJS