A modular Node.js + Express + MongoDB backend template with authentication and utilities.
This boilerplate is designed to help contributors and developers quickly set up, extend, and maintain backend APIs.
src/
βββ controllers/ # Route controllers (business logic)
βββ db/ # Database connection setup
βββ middlewares/ # Express middlewares (auth, validation, etc.)
βββ models/ # Mongoose models (e.g., User.models.js)
βββ routes/ # API routes (e.g., healthCheck, user)
βββ util/ # Helpers (ApiError, ApiResponse, asyncHandler, constants)
βββ app.js # Express app initialization
βββ index.js # Entry point
β Express server setup
β MongoDB with Mongoose models
β Error handling with ApiError and asyncHandler
β Standardized API responses with ApiResponse
β JWT-based authentication (Access + Refresh tokens)
β Clean modular folder structure
- Clone the repo (Fork first)
git clone https://github.com/your-username/backend-model.gitcd backend-model- Install dependencies
npm install- Configure environment variables
Copy the .env.example file to .env.local:
cp .env.local .envOpen .env and fill in your secrets:
- Run the server
npm run devThe server will start on http://localhost:4000 (or the port you set).
-
Register: POST /api/v1/users/register
-
Login: POST /api/v1/users/login
-
Access token: Short-lived (1h), used for protected routes
-
Refresh token: Long-lived (10d), stored in DB + HTTP-only cookie