A robust, production-ready Node.js backend boilerplate built with Express, TypeScript, and MongoDB. This starter pack is designed to be brand-neutral and highly extensible for any backend service.
- TypeScript Core: Fully typed development experience.
- Interactive API Documentation: Real-time Swagger UI documentation.
- Simplified Authentication: Direct registration and login flow with JWT token generation and automated welcome emails.
- RESTful API Design: Structured routing and controller architecture.
- Mongoose Integration: Ready-to-use MongoDB schemas and models.
- Request Validation: Robust input validation using Zod.
- Email Integration: Integrated with SendPulse for automated notifications.
- Advanced Logging: Structured logging using Pino and Pino-pretty.
- API Documentation: Pre-configured
.httpfiles for testing with the REST Client extension. - Security: Basic rate limiting and CORS configuration included.
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: MongoDB (via Mongoose)
- Validation: Zod
- Authentication: JSON Web Tokens (JWT)
- Logging: Pino
- Email Service: SendPulse API
src/
├── controllers/ # API request handlers
├── docs/ # API testing/documentation (.http files)
├── enums/ # Application-wide enums and constants
├── interfaces/ # TypeScript interfaces and types
├── mails/ # Generic email templates (HTML/CSS)
├── middleware/ # Auth checks, rate limiters, etc.
├── models/ # Mongoose schemas and database logic
├── routes/ # Express route declarations
├── services/ # Business logic and external service integrations
├── utils/ # Database connection, JWT helpers, and logger
└── validation/ # Schema-based request validation (Zod)
Create a .env file in the root directory and configure the following variables:
# Server
PORT=4000
BASE_URL=/api
# Database
MONGO_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/database
# Security
JWT_SECRET=your_very_secure_random_string
# Email (SendPulse)
SENDPULSE_USER_ID=your_id
SENDPULSE_SECRET=your_secret
SENDER_NAME="API Support"
SENDER_EMAIL=no-reply@yourdomain.com-
Install dependencies:
npm install
-
Configure Environment: Duplicate
.env.example(if provided) or create a new.envfile as shown above. -
Start Development Server:
npm run dev
-
Build for Production:
npm run build
-
Start Production Server:
npm start
This project provides two ways to test and view the API documentation:
Once the server is running, you can access the interactive Swagger documentation at:
http://localhost:4000/docs
This interface allows you to view all available endpoints, their required parameters, and execute requests directly from your browser.
For those who prefer testing within VS Code, an auth.docs.http file is provided in the src/docs/ directory. Use the VS Code REST Client extension to execute requests directly from the editor.
npm run dev: Hot-reloading development server (ts-node-dev).npm run build: Compiles TypeScript to thedist/directory.npm start: Runs the compiled JavaScript with standard Node.npm run gcp-build: Standardized build script for cloud platforms like GCP or Render.
Created as a generic starter for building scalable backend services.