rest-setup
Version:
A ready-to-use REST API backend structure built with Node.js and Express โ includes organized folders for controllers, routes, models, and middlewares.
288 lines (216 loc) โข 8.16 kB
Markdown
<div align="center">

Create production-ready Node.js backends in seconds! A modern, feature-rich backend bootstrapper with best practices baked in.
[](https://github.com/vi5halsingh/rest-setup/blob/main/LICENSE)
[](https://www.npmjs.com/package/rest-setup)
[](https://github.com/vi5halsingh/rest-setup/pulls)
[](https://www.npmjs.com/package/rest-setup)
[](
[](
[](
[](
[](
</div>
---
- ๐จ **Clean Architecture**: Following industry-standard MVC patterns
- ๐ **Security First**: Built-in security best practices
- ๐ฆ **Zero Config**: Start coding in seconds
- ๐ ๏ธ **Developer Experience**: Hot reload, error handling, and more
- ๐ **Plug & Play**: Cloudinary, MongoDB, and more integrations
- ๐ **Type Safety**: Optional TypeScript support
```bash
npx rest-setup my-api
npx rest-setup .
```
```
๐ฏ Initializing rest-setup...
โก๏ธ Creating project structure
โโ Setting up MVC architecture
โโ Configuring security middleware
โโ Adding error handlers
โโ Installing dependencies
๐จ Customizing your setup
โโ Generating .env file
โโ Setting up MongoDB connection
โโ Configuring Cloudinary
โโ Adding TypeScript (optional)
๐ Launching development server
โโ Available at http://localhost:8000
Happy coding! ๐
```
### System Requirements
- Node.js 14+ ([Download](https://nodejs.org/))
- MongoDB ([Download](https://www.mongodb.com/try/download/community) or [Atlas](https://www.mongodb.com/atlas/database))
- Git ([Download](https://git-scm.com/))
## โก๏ธ Quick Start Guide
### 1. Configure Environment
```bash
cd my-api
cp .env.example .env
```
Edit `.env` with your settings:
```env
# ๏ฟฝ Essential Configuration
PORT=8000
NODE_ENV=development
MONGODB_URI=your_mongodb_uri
CLOUDINARY_NAME=your_cloud_name
CLOUDINARY_KEY=your_api_key
CLOUDINARY_SECRET=your_api_secret
```
```bash
npm install
npm run dev
npm start
```
- **MVC Architecture**: Clean separation of concerns
- **Express.js**: Fast, unopinionated web framework
- **MongoDB Integration**: Ready-to-use database setup
- **Error Handling**: Standardized error responses
- **File Upload**: Built-in file handling with Multer
- **Cloudinary**: Image upload and storage integration
- **CORS**: Configurable cross-origin settings
- **Cookie Parser**: HTTP cookie handling
- **Request Parsing**: JSON and URL-encoded bodies
- **Static Files**: Serve static content
- **Organized Structure**: Clear project layout
- **API Response**: Standardized JSON responses
- **Environment Config**: Easy .env configuration
- **Prettier**: Code formatting included
```bash
๐ฆ rest-setup
โโ ๐ src/
โ โโ ๐ app.js
โ โโ ๐ index.js
โ โโ ๏ฟฝ constants.js
โ โโ ๐ controllers/
โ โ โโ ๐ user.controller.js
โ โโ ๐ models/
โ โ โโ ๐ user.model.js
โ โโ ๐ routes/
โ โ โโ ๐ user.routes.js
โ โโ ๐ middlewares/
โ โ โโ ๐ multer.middleware.js
โ โโ ๐ db/
โ โ โโ ๐ db.js
โ โโ ๐ utils/
โ โโ ๐ apiError.js
โ โโ ๐ apiResponse.js
โ โโ ๐ cloudinary.js
โโ ๐ public/
โ โโ ๐ temp/
โโ ๐ .env.example
โโ ๐ .gitignore
โโ ๐ .prettierrc
โโ ๐ package.json
```
```javascript
// Configure multer middleware
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "./public/temp")
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
export const upload = multer({
storage,
})
// Use in routes
router.post("/upload",
upload.single("file"),
uploadToCloudinary
);
```
```javascript
class ApiError extends Error {
constructor(
statusCode,
message= "Something went wrong",
errors = [],
stack = ""
){
super(message)
this.statusCode = statusCode
this.data = null
this.message = message
this.success = false;
this.errors = errors
if (stack) {
this.stack = stack
} else{
Error.captureStackTrace(this, this.constructor)
}
}
}
// Usage in controllers
if (!user) {
throw new ApiError(404, "User not found")
}
```
We love your input! We want to make contributing as easy and transparent as possible. Check out our [Contributing Guide](CONTRIBUTING.md) for detailed guidelines.
1. Fork the repo and create your branch from `main`
2. Install dependencies: `npm install`
3. Add your changes
4. Run tests: `npm test`
5. Submit a PR!
We use ESLint and Prettier to maintain code quality. Before committing:
```bash
npm run format
npm run lint
npm run test
```
- [API Documentation](docs/API.md)
- [Security Guide](docs/SECURITY.md)
- [Deployment Guide](docs/DEPLOYMENT.md)
- [Change Log](CHANGELOG.md)
[](https://github.com/vi5halsingh/rest-setup/stargazers)
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
<a href="https://www.buymeacoffee.com/vi5halsingh" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="150">
</a>
<div align="center">
[](https://github.com/vi5halsingh)
[](https://x.com/Vi5hu_)
[](https://linkedin.com/in/vi5halsingh)
[](https://github.com/vi5halsingh/rest-setup/issues) ยท
[](https://github.com/vi5halsingh/rest-setup/issues)
</div>
---
<div align="center">
Made with code and coffee by <a href="https://github.com/vi5halsingh">Vishal Singh</a>
If you found this project helpful, please consider giving it a โญ๏ธ
</div>