node-backend-generator
v1.2.4
Published
π CLI tool to generate professional Node.js backend templates with best practices, multiple databases, authentication, and production-ready features
Maintainers
Readme
Node Backend Generator π
A powerful CLI tool to generate professional, production-ready Node.js backend templates in seconds.
Choose your database, features, and get a complete backend with industry best practices.
β¨ Features
- π Multiple Databases β MongoDB (Mongoose), MySQL/PostgreSQL (Sequelize), Prisma, or Database-less
- π Authentication β JWT with refresh tokens, bcrypt password hashing
- π File Upload β Multer with validation & multiple file support
- π§ Email Service β Nodemailer with ready templates (welcome, password reset, notifications)
- π API Documentation β Auto-generated Swagger/OpenAPI docs
- π³ Docker Support β Dockerfile + docker-compose with database setup
- π‘οΈ Security β Helmet, CORS, rate limiting, input validation
- β‘ Modern JS β ES Modules & CommonJS support
- π― Production Ready β Error handling, logging, environment config
π Quick Start
Using npx (Recommended β No Installation Needed)
npx node-backend-generator@latestGlobal Installation
npm install -g node-backend-generator
create-node-backendLocal Installation
npm install node-backend-generator
npx create-node-backendπ§ Usage
1οΈβ£ Run the Generator
npx node-backend-generator@latest2οΈβ£ Follow the Interactive Prompts
Youβll be guided through setting up your project:
Enter your project name: my-awesome-apiExample Interactive Setup:
? Enter your project name: my-awesome-api
? Choose module system:
β― ES Modules (MJS)
CommonJS (CJS)
? Choose database ORM:
β― Mongoose (MongoDB)
Sequelize (MySQL/PostgreSQL)
Prisma (Multi-database)
None (API only)
? Select additional features:
β Authentication (JWT)
β API Documentation (Swagger)
β― File Upload (Multer)
β― Email Service (Nodemailer)
β― Docker Support
β Rate Limiting
β Input Validation3οΈβ£ Generated Project Structure
my-awesome-api/
βββ server.js
βββ package.json
βββ .env
βββ .env.example
βββ .gitignore
βββ Dockerfile
βββ docker-compose.yml
βββ src/
β βββ config/
β βββ controllers/
β βββ models/
β βββ routes/
β βββ middlewares/
β βββ services/
β βββ utils/
βββ uploads/
βββ tests/4οΈβ£ Get Started with Your New Project
cd my-awesome-api
npm install
cp .env.example .env
# Prisma only
npx prisma generate
npx prisma db push
# Start development server
npm run dev
# Or production
npm startπ― Available Scripts
npm start # Start production server
npm run dev # Start development server with nodemon
npm test # Run tests
npm run lint # Lint code
npm run lint:fix # Auto-fix lint issuesπ API Endpoints
π Authentication (if enabled)
POST /api/auth/register # Register user
POST /api/auth/login # Login user
GET /api/auth/profile # Get logged-in profileπ€ User Routes
GET /api/users
GET /api/users/:idπ File Upload (if enabled)
POST /api/upload/single
POST /api/upload/multipleπ§ Email Service (if enabled)
POST /api/email/test
POST /api/email/password-reset
POST /api/email/welcomeπ§° Utilities
GET /health
GET /api-docsπ§ Configuration
Environment Variables (.env)
# Server
NODE_ENV=development
PORT=3000
# Database
MONGODB_URI=mongodb://localhost:27017/your-db
# OR
DATABASE_URL="mysql://root:password@localhost:3306/your-db"
# JWT
JWT_SECRET=your_super_secret_key
JWT_EXPIRES_IN=7d
# Email
SMTP_HOST=your-smtp-host
SMTP_PORT=587
[email protected]
SMTP_PASS=your-passwordποΈ Database Setup
MongoDB (Mongoose)
- Install MongoDB or use Atlas.
- Update
MONGODB_URIin.env. - Done! No schema migration needed.
MySQL / PostgreSQL (Sequelize)
- Install the respective DB.
- Create your database.
- Update
.envcredentials.
Prisma
npx prisma generate
npx prisma db pushπ³ Docker Support
If you selected Docker:
docker-compose up -d # Start DB & app
docker build -t my-backend .
docker run -p 3000:3000 my-backendπ Authentication Usage
Register a User
POST /api/auth/register
{
"name": "John Doe",
"email": "[email protected]",
"password": "securepassword"
}Login
POST /api/auth/login
{
"email": "[email protected]",
"password": "securepassword"
}Protected Routes
Include JWT token in headers:
Authorization: Bearer <your_jwt_token_here>π File Upload Example
const formData = new FormData();
formData.append('file', fileInput.files[0]);
fetch('/api/upload/single', {
method: 'POST',
headers: { Authorization: 'Bearer your-token' },
body: formData,
});π§ Email Service Example
Send Test Email
POST /api/email/test
{
"email": "[email protected]"
}Request Password Reset
POST /api/email/password-reset
{
"email": "[email protected]"
}π οΈ Customization
Add a New Route
- Create a controller in
src/controllers/ - Add a route in
src/routes/ - Import it in
server.js
Add a New Model
- Add a model in
src/models/ - Use it in your controller logic
Add Middleware
- Create in
src/middlewares/ - Register globally or per-route in
server.js
π€ Support
- π Docs: Visit
/api-docsafter starting your server - π Issues: GitHub Issues
- π¬ FAQ: See in docs or discussions
π License
MIT License β see LICENSE for details.
π Contributing
We welcome contributions!
Please read our Contributing Guide before submitting PRs.
β¨ Happy Coding! β¨
Generated with β€οΈ by Trina Dasgupta
