gen-express-backend
v1.2.0
Published
CLI to generate express backend template
Downloads
25
Maintainers
Readme
gen-express-backend
gen-express-backend is a CLI tool that instantly generates a production-ready Express + MongoDB backend with JWT authentication, controllers, routes, models, middleware, and clean project structure.
Create a full backend project in one command.
🚀 Features
- Clean Express project structure
- MongoDB + Mongoose configuration
- JWT-based Authentication (Signup / Login / Logout)
- Password hashing with bcrypt
- Protected routes using auth middleware
- User model with email & password
- Global error handling middleware
- Auto-generated
.envfile - Nodemon for development
- Beginner-friendly, scalable structure
📦 Installation
Run directly using npx (recommended):
npx gen-express-backend myapp
Or install globally:
npm install -g gen-express-backend gen-express-backend myapp
📁 Project Structure
The generated project looks like this:
myapp/ ├── src/ │ ├── app.js │ ├── server.js │ ├── config/ │ │ └── db.js │ ├── controllers/ │ │ ├── authController.js │ │ └── userController.js │ ├── routes/ │ │ ├── authRoutes.js │ │ └── userRoutes.js │ ├── models/ │ │ └── User.js │ ├── middleware/ │ │ ├── authMiddleware.js │ │ └── errorMiddleware.js │ └── utils/ │ └── generateToken.js ├── .env └── package.json
🛠 Usage
1. Create a new project
npx gen-express-backend myapp
2. Install dependencies
cd myapp npm install
3. Start development server
npm run dev
Server runs at:
http://localhost:5000
🔐 Authentication API
POST /api/auth/signup
Creates a new user and returns JWT token.
POST /api/auth/login
Logs in user and returns JWT token.
POST /api/auth/logout
Logs out user (stateless JWT).
🔌 Protected Routes
GET /api/users
Returns all users (JWT protected).
Add header:
Authorization: Bearer <your_token>
🌱 Environment Variables
A default .env file is created:
PORT=5000 MONGO_URI=mongodb://localhost:27017/testdb JWT_SECRET=supersecretjwtkey
Change JWT_SECRET in production.
📄 Requirements
- Node.js v14+
- MongoDB (local or cloud)
🤝 Contributing
Issues and pull requests are welcome to improve this CLI.
📜 License
MIT License
Copyright © 2025
