npm package: @payal9913/create-node-backend
Description: A CLI tool to generate Node.js backend boilerplates
Author: Payal suthar
Latest version: 2.0.0

# 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

```bash
# 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 start
```

### Manual Setup

1. Clone this repository
2. Install dependencies: `npm install`
3. Configure environment variables (see below)
4. 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_secret
```

### Getting Cloudinary Credentials

To use the file upload functionality with Cloudinary:

1. Sign up at [Cloudinary](https://cloudinary.com/)
2. Navigate to your dashboard
3. 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
└── .env
```

## Available Scripts

- `npm start` - Starts the server with nodemon for development
- `npm test` - Runs the test suite

## API Endpoints

### Authentication

- `POST /api/auth/register` - Register a new user
- `POST /api/auth/login` - Login an existing user
- `POST /api/auth/refresh-token` - Get a new access token using refresh token
- `POST /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! 🚀