create-backend-buddy
v1.1.2
Published
Scaffold modern Node.js backends with your preferred stack
Downloads
61
Maintainers
Readme
🚀 create-backend-buddy
🏗️ Scaffold a modern Node.js + Express backend in seconds
Your complete backend starter with ORM, database, security, logging, Swagger docs, and more
Quick Start • Features • Installation • Documentation
✨ Features
🛡️ Security First
- Helmet.js - HTTP security headers
- CORS - Configurable cross-origin requests
- Rate Limiting - Prevent API abuse
- Input Validation - Built-in sanitization
🗄️ Database Flexibility
- PostgreSQL - Production-ready relational DB
- MySQL - Popular relational database
- MongoDB - NoSQL document database
- SQLite - Lightweight development DB
🧰 Developer Experience
- TypeScript - Full type safety support
- Hot Reload - Instant development feedback
- Swagger UI - Interactive API documentation
- Structured Logging - Pino-powered logging
🚢 Production Ready
- Docker - Containerized deployment
- Environment Config - Secure configuration
- Error Handling - Centralized error management
- Git Integration - Automatic repository setup
🚀 Quick Start
Option 1: Global Installation
npm install -g create-backend-buddy
create-backend-buddyOption 2: NPX (Recommended)
npx create-backend-buddy🎯 Interactive Setup
┌─────────────────────────────────────────┐
│ │
│ 🚀 Welcome to Backend Buddy! │
│ │
└─────────────────────────────────────────┘
✔ Project name: › my-awesome-api
✔ Language: › TypeScript
✔ ORM/ODM: › Prisma
✔ Database: › PostgreSQL
✔ Include Swagger docs? › Yes
✔ Include Docker support? › Yes
✔ Initialize Git repo? › Yes
🎉 Creating your backend...🏃♂️ Launch Your Project
cd my-awesome-api
npm install
npm run dev🎉 That's it! Your backend is running at
http://localhost:3000
📦 Installation Options
# Install globally
npm install -g create-backend-buddy
# Use anywhere
create-backend-buddy my-project# Use directly without installing
npx create-backend-buddy my-project
# Or run interactively
npx create-backend-buddynpx create-backend-buddy \
--name my-api \
--lang typescript \
--orm prisma \
--db postgres \
--swagger \
--docker \
--git🏗️ Project Structure
my-awesome-api/
├── 📁 src/
│ ├── 📁 controllers/ # Request handlers
│ │ └── 📁 prisma/ # ORM-specific controllers
│ ├── 📁 lib/ # Database connections
│ ├── 📁 routes/ # API route definitions
│ │ └── user.route.js
│ ├── 📁 utils/ # Utility functions
│ │ ├── logger.js # Pino logger setup
│ │ ├── ApiError.js # Custom error class
│ │ └── responder.js # Response formatter
│ ├── swagger.js # Swagger configuration
│ └── index.js # Application entry point
├── 📁 prisma/ # Database schema (if Prisma)
│ └── schema.prisma
├── 📁 generated/ # Auto-generated files
├── 📁 logs/ # Application logs
├── 🐳 docker-compose.yml # Docker services
├── 🐳 Dockerfile # Container definition
├── 📋 swagger.yaml # API documentation
├── ⚙️ .env.example # Environment template
├── 📦 package.json
└── 🙈 .gitignore🛠️ Technology Stack
Core Framework
| Technology | Purpose | Version |
|------------|---------|---------|
| | Runtime | 16+ |
|
| Web Framework | Latest |
|
| Type Safety | Latest |
Database & ORM Options
| ORM/ODM | Databases | Features | |---------|-----------|----------| | Prisma | PostgreSQL, MySQL, SQLite | Type-safe, Auto-migration | | Sequelize | PostgreSQL, MySQL, SQLite | Feature-rich, Mature | | Mongoose | MongoDB | Schema-based, ODM |
Security & Middleware
- 🛡️ Helmet - Security headers
- 🌐 CORS - Cross-origin resource sharing
- ⏱️ Rate Limiting - API abuse prevention
- 📝 Morgan - HTTP request logging
🔧 Available Scripts
| Command | Description |
|---------|-------------|
| npm run dev | 🔥 Start development server with hot reload |
| npm run build | 🏗️ Build TypeScript project |
| npm start | 🚀 Start production server |
| npm run generate | ⚙️ Generate Prisma client |
| docker-compose up | 🐳 Run with Docker containers |
📚 What's Included
🔐 Security Middleware
// Automatic security setup
app.use(helmet());
app.use(cors({ origin: allowedOrigins }));
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));📊 Structured Logging
// Pino logger with file rotation
logger.info('Server started on port 3000');
logger.error('Database connection failed', { error });🎯 Error Handling
// Centralized error management
class ApiError extends Error {
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode;
}
}📖 API Documentation
- Swagger UI available at
/api/docs - Interactive API explorer
- Automatic schema generation
🚀 Quick Examples
Creating a New Route
// src/routes/posts.route.js
const express = require('express');
const router = express.Router();
router.get('/', async (req, res) => {
try {
const posts = await Post.findAll();
res.json(ApiResponse.success(posts));
} catch (error) {
res.status(500).json(ApiResponse.error(error.message));
}
});
module.exports = router;Database Model (Prisma)
// prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
createdAt DateTime @default(now())
}🌍 Environment Configuration
# .env.example
NODE_ENV=development
PORT=3000
# Database
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"
# Security
JWT_SECRET=your-super-secret-jwt-key
CORS_ORIGIN=http://localhost:3000
# Logging
LOG_LEVEL=info🐳 Docker Support
Quick Start with Docker
# Build and run
docker-compose up --build
# Run in detached mode
docker-compose up -dDocker Configuration
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
depends_on:
- db
db:
image: postgres:13
environment:
- POSTGRES_DB=myapi
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🌟 Star this project if it helped you!
Made with ❤️ by the Backend Buddy team
