This is a Node.js Express TypeScript boilerplate designed to follow a structured architecture similar to NestJS, making it highly scalable, maintainable, and modular.
It is built with best practices in mind, incorporating Prisma ORM, Swagger API documentation, Redis caching, and Winston logging.
Unlike basic Express.js boilerplates that lack structure and scalability, this boilerplate offers:
β
Modular Architecture β Inspired by NestJS, separating concerns into controllers
, services
, and routes
.
β
Pre-configured TypeScript β Ensuring type safety, better development experience, and maintainability.
β
Built-in Authentication β Includes JWT authentication out of the box.
β
Prisma ORM Integration β Provides an easy-to-use and scalable database management system.
β
Redis Caching β Optimized for performance with ioredis
for caching.
β
Centralized Logging β Uses winston
for logging with MongoDB and file-based storage.
β
API Documentation β Auto-generated API documentation using swagger-ui-express
.
β
Security Best Practices β Pre-configured helmet
, hpp
, cors
, and rate limiting for enhanced security.
β
Unit Testing Setup β Pre-configured with Jest & Supertest.
β
Production-Ready β Includes scripts for deployment and Docker support (if needed).
- Express.js - Minimal and fast web framework.
- TypeScript - Static typing for better maintainability.
- Prisma ORM - Database management with migrations and type safety.
- Swagger - API documentation (
swagger-ui-express
). - Redis - Caching for improved performance (
ioredis
). - Winston - Logging to both files and MongoDB.
- JWT Authentication - Secure authentication flow.
- Security Middleware -
helmet
,hpp
,cors
, rate limiting, and more. - File Uploads -
multer
integration for handling file uploads. - Testing Framework - Uses Jest & Supertest.
- ESLint & Prettier - Code linting and formatting.
git clone https://github.com/TKAkhter/advance-expressjs-boilerplate.git
cd advance-expressjs-boilerplate
npm install
Create a .env
file and configure necessary variables:
DATABASE_URL=your_database_url
REDIS_URL=your_redis_url
JWT_SECRET=your_jwt_secret
npm run dev
npm run build
npm start
npm test
npm run lint
npm run prettier
npm run prisma:gen # Generate Prisma client
npm run prisma:push # Push schema to the database
This project follows a modular and scalable structure, similar to NestJS.
/src
βββ controllers/ # Handles HTTP requests and responses
βββ services/ # Business logic and database interactions
βββ middleware/ # Express middlewares for security, logging, etc.
βββ models/ # Database models (Prisma schemas)
βββ routes/ # API route definitions
βββ utils/ # Utility functions and helpers
βββ config/ # Configuration files (env, database, etc.)
βββ tests/ # Unit and integration tests
βββ server.ts # Application entry point
- Controllers β Handle incoming requests and return responses.
- Services β Contain the business logic and interact with the database via Prisma.
- Middleware β Includes authentication, logging, and security layers.
- Routes β Define API endpoints, connecting controllers to Express.
- Models β Represent the database schema using Prisma.
- Utils β Common utility functions like error handling, response formatting, etc.
- Config β Stores configuration variables (like env settings).
Swagger documentation is auto-generated and available at:
http://localhost:3000/api-docs
This project follows Semantic Versioning (vX.Y.Z
) with automatic tags and releases on every PR merged into main
.
Change Type | Keyword in PR Title/Body | Example Version Change |
---|---|---|
Major Update | #major |
v1.0.0 β v2.0.0 |
Minor Update | #minor |
v1.0.0 β v1.1.0 |
Patch Update | (Default, no keyword) | v1.0.0 β v1.0.1 |
π PR Title: Fixed authentication bug
π PR Body: "Resolved a minor issue in login flow."
πΉ Result: v1.0.0 β v1.0.1
π PR Title: Added new profile feature #minor
π PR Body: "Implemented user profile page."
πΉ Result: v1.0.0 β v1.1.0
π PR Title: Revamped API structure #major
π PR Body: "Breaking changes: Updated API structure."
πΉ Result: v1.0.0 β v2.0.0
When a PR is merged into main
, GitHub Actions runs the release workflow.
It checks the PR title and body for #major
or #minor
.
Creates a new tag and GitHub release based on the versioning rule.
- Ensure the GitHub workflow file is in place at
.github/workflows/release.yml
. - Create PRs with meaningful titles & descriptions.
- Merge the PR into
main
, and a new version tag & release will be created automatically.
This project can be easily containerized using Docker. A Dockerfile
can be created as follows:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "start"]
EXPOSE 3000
Ensure to set the correct environment variables and use a process manager like pm2
:
pm2 start dist/server.js --name "express-app"
pm2 save
pm2 startup
This project is licensed under the MIT License.