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