A production-ready NestJS boilerplate with TypeORM, PostgreSQL, Redis, BullMQ, and comprehensive email system.
- Node.js v18 or higher
- PostgreSQL running locally
- Redis running locally
- npm (included with Node.js)
npm run setup:fullThis single command will:
- β Check Node.js and npm versions
- β Install all dependencies
- β Create required directories
- β Build the project
- β Set up the database (migrations + seeds)
npm run setupUpdate your .env file with proper configuration:
# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password
DB_DATABASE=your_db_name
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT
JWT_SECRET=your_jwt_secret
# Mail Configuration
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USER=your_email@gmail.com
MAIL_PASS=your_app_passwordnpm run setup:dbnpm run start:dev| Script | Description |
|---|---|
npm run start:dev |
Start development server with hot reload |
npm run start:debug |
Start with debugging enabled |
npm run build |
Build the project |
npm run clean |
Clean build artifacts |
| Script | Description |
|---|---|
npm run lint |
Lint and auto-fix code |
npm run lint:check |
Check linting without fixing |
npm run format |
Format code with Prettier |
npm run format:check |
Check formatting without fixing |
npm run precommit |
Run all checks before commit |
| Script | Description |
|---|---|
npm run migration:generate --name=migration-name |
Generate new migration |
npm run migration:run |
Run pending migrations |
npm run migration:revert |
Revert last migration |
npm run migration:show |
Show migration status |
npm run seed:generate --name=seed-name |
Generate new seed |
npm run seed:run |
Run seed scripts |
| Script | Description |
|---|---|
npm run test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
npm run test:cov |
Run tests with coverage |
npm run test:e2e |
Run end-to-end tests |
| Script | Description |
|---|---|
npm run setup |
Initial project setup |
npm run setup:db |
Database setup only |
npm run setup:full |
Complete setup (setup + db) |
npm run clean:install |
Clean and reinstall dependencies |
src/
βββ common/ # Shared entities and repositories
βββ config/ # Configuration files
βββ constants/ # Application constants
βββ decorators/ # Custom decorators
βββ exceptions/ # Custom exceptions
βββ filters/ # Exception filters
βββ guards/ # Route guards
βββ interceptors/ # Response interceptors
βββ middleware/ # Custom middleware
βββ modules/ # Feature modules
β βββ auth/ # Authentication module
β βββ profile/ # User profile module
β βββ queue/ # Queue management
β βββ user/ # User management
βββ pipes/ # Validation pipes
βββ redis/ # Redis configuration
βββ routes.ts # Route definitions
βββ shared/ # Shared services
βββ templates/ # Email templates
βββ types/ # TypeScript type definitions
βββ utils/ # Utility functions
- β NestJS Framework - Modern Node.js framework
- β TypeORM - Type-safe database ORM
- β PostgreSQL - Robust relational database
- β Redis - Caching and session storage
- β BullMQ - Background job processing
- β JWT Authentication - Secure token-based auth
- β Email System - Comprehensive email handling
- β Validation - Request validation with class-validator
- β Swagger - API documentation
- β Rate Limiting - Request throttling
- β Security - Helmet, CORS, compression
- β Multiple Templates - Handlebars-based templates
- β Queue Processing - Background email sending
- β Multiple Recipients - Send to admin and user simultaneously
- β Development Mode - Console output for testing
- β Migrations - Version-controlled schema changes
- β Seeds - Sample data population
- β Repository Pattern - Clean data access layer
- β Entity Relationships - Proper database relationships
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/refresh- Refresh token
GET /profile- Get user profilePUT /profile- Update user profile
- Email jobs are processed automatically via BullMQ
- Templates:
get-in-touch,get-in-touch-confirmation,welcome-email
Email: admin@mail.com
Password: defaultPass123!
Create a .env file based on .env.example:
# Application
NODE_ENV=development
PORT=4000
# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASE=nestjs_boilerplate
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d
# Mail Configuration
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USER=your-email@gmail.com
MAIL_PASS=your-app-password
MAIL_FROM_NAME=Your App Name
MAIL_FROM_EMAIL=noreply@yourapp.com
MAIL_TO_NAME=Admin
MAIL_TO_EMAIL=admin@yourapp.comnpm run build
npm run start:prod# Build image
docker build -t nestjs-boilerplate .
# Run container
docker run -p 4000:4000 nestjs-boilerplate- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the UNLICENSED License.
-
Database Connection Failed
- Ensure PostgreSQL is running
- Check database credentials in
.env - Verify database exists
-
Redis Connection Failed
- Ensure Redis is running
- Check Redis configuration in
.env
-
Build Errors
- Run
npm run clean - Check Node.js version (18+)
- Build again
- Run
-
Migration Errors
- Check database connection
- Verify migration files are valid
- Run
npm run migration:showto check status
- Check the logs for detailed error messages
- Ensure all prerequisites are installed
- Verify environment configuration
- Check database and Redis connections