@payal9913/create-node-backend
v2.0.0
Published
A CLI tool to generate Node.js backend boilerplates
Maintainers
Readme
Node js Backend Boilerplate
A modern Node.js backend boilerplate with Express.js, MongoDB, authentication, file uploads, and more.
Features
- 🔐 Authentication with JWT (Access & Refresh tokens)
- 📁 File uploads with Multer & Cloudinary integration
- 🧩 Modular architecture (MVC pattern)
- 🛡️ Middleware for authentication and error handling
- 📝 Comprehensive API error handling
- 🔄 MongoDB connection with Mongoose
- 💬 Real-time communication using Socket.IO
- ⚡ Async/await patterns with proper error handling
Quick Start
Install using NPM
# Create a new project
npx @payal9913/create-node-backend your_folder_name
# Navigate to the project
cd your_folder_name
# Install dependencies
npm install
# Start development server
npm startManual Setup
- Clone this repository
- Install dependencies:
npm install - Configure environment variables (see below)
- Start the server:
npm start
Environment Variables
Create a .env file in the root directory with the following variables:
NODE_ENV == "dev"
PORT=8000
MONGODB_URI=your_mongodb_connection_string
CORS_ORIGIN=*
# JWT Configuration
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFERESH_TOKEN_SECRET=your_refresh_token_secret
REFERESH_TOKEN_EXPIRY=10d
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secretGetting Cloudinary Credentials
To use the file upload functionality with Cloudinary:
- Sign up at Cloudinary
- Navigate to your dashboard
- Copy your Cloud Name, API Key, and API Secret to your .env file
Project Structure
├── core/
│ ├── config/
│ │ ├── constant.js
│ │ └── db.js
│ ├── controllers/
│ │ └── authentication.controller.js
│ ├── middlewares/
│ │ ├── auth.middleware.js
│ │ └── fileuploader.middleware.js
│ ├── models/
│ │ └── user.models.js
│ ├── routes/
│ │ └── authentication.routes.js
│ ├── utils/
│ │ ├── apiError.js
│ │ ├── apiResponse.js
│ │ ├── asyncHandler.js
│ │ └── cloudinary.js
│ ├── app.js
│ └── server.js
├── package.json
└── .envAvailable Scripts
npm start- Starts the server with nodemon for developmentnpm test- Runs the test suite
API Endpoints
Authentication
POST /api/auth/register- Register a new userPOST /api/auth/login- Login an existing userPOST /api/auth/refresh-token- Get a new access token using refresh tokenPOST /api/auth/logout- Logout the user
File Uploads
This boilerplate includes middleware for handling file uploads with Multer and storing them on Cloudinary. See the fileuploader.middleware.js for implementation details.
Error Handling
The API includes a comprehensive error handling system with custom error classes and middleware for consistent error responses.
Security Best Practices
- JWT-based authentication
- Password hashing
- Protected routes with middleware
- CORS configuration
- Request validation
License
ISC
Author
Payal Suthar
Happy coding! 🚀
