A production-ready backend boilerplate built with Node.js, TypeScript, Express, MongoDB, and Redis. This project provides a solid foundation for building scalable REST APIs with modern best practices and developer-friendly tooling.
- TypeScript - Full TypeScript support with strict type checking
- Express.js - Fast, unopinionated web framework
- MongoDB - NoSQL database integration with Mongoose ODM
- Redis - In-memory data store for caching
- Security - Helmet.js for securing Express apps
- CORS - Cross-Origin Resource Sharing enabled
- Compression - Response compression middleware
- Hot Reload - Fast development with ts-node-dev
- Path Aliases - Clean imports with TypeScript path mapping
- ESLint - Code quality and style checking
- Environment Variables - Configuration management with dotenv
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- MongoDB (running locally or remote connection)
- Redis (running locally or remote connection)
- Clone the repository
git clone <repository-url>
cd boilerplate-node- Install dependencies
npm install- Configure environment variables
Create a .env file in the root directory:
PORT=3003
MONGODB_URI=mongodb://127.0.0.1:27017/your-database-name
WORKER=mainRun with hot-reload enabled:
npm run devStart the application:
npm startCompile TypeScript to JavaScript:
npm run buildThe compiled files will be in the dist directory.
boilerplate-node/
├── src/
│ ├── index.ts # Application entry point
│ ├── system/ # Core system modules
│ │ ├── config.ts # Configuration management
│ │ ├── express.ts # Express server setup
│ │ ├── mongo.ts # MongoDB connection
│ │ ├── redis.ts # Redis connection
│ │ └── index.ts # System module exports
│ └── workloads/ # Business logic and routes
│ └── index.ts # Workload entry point
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3003 |
MONGODB_URI |
MongoDB connection string | mongodb://127.0.0.1:27017/casino |
WORKER |
Worker identifier | - |
The project uses modern TypeScript settings:
- Target: ESNext
- Module: NodeNext
- Strict mode: Enabled
- Path aliases:
src/*for clean imports
- Initialize - Connect to MongoDB and Redis
- Configure - Load Express middlewares (Helmet, CORS, Compression)
- Run - Start the HTTP server
- Load - Initialize workloads and routes
The Express server is configured with:
- Helmet - Security headers
- Compression - Response compression
- JSON Parser - Request body parsing
- URL Encoder - Form data parsing
- CORS - Cross-origin requests
Run ESLint to check code quality:
npm run lintAdd your routes and business logic in the src/workloads directory. Import and initialize them in src/index.ts.
Use clean imports with the src/* alias:
import { config } from "src/system/config";
import { someUtil } from "src/utils/helper";The build process:
- Removes the old
distdirectory - Compiles TypeScript files to JavaScript
- Outputs to the
distdirectory
express- Web frameworkmongoose- MongoDB ODMredis- Redis clientdotenv- Environment configurationhelmet- Security middlewarecors- CORS middlewarecompression- Response compressionethers- Ethereum librarycron- Job schedulingcross-fetch- Cross-platform fetch
typescript- TypeScript compilerts-node- TypeScript executionts-node-dev- Development with hot reloadeslint- Code linting@typescript-eslint/*- TypeScript ESLint support
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request