node-starter-cli

node-starter-cli
is an open-source command‑line tool that bootstraps a production‑ready Node.js REST API in seconds. It saves you from repetitive boilerplate—complete with authentication, JWT flows, rate limiting, and a modular folder structure.
🌟 Features
- One‑command scaffolding: Instantly generate a complete Express + MongoDB backend.
- Built‑in authentication: Email/password register & login routes with JWT + refresh‑token flows.
- Auto‑generated secrets:
JWT_SECRET
& REFRESH_TOKEN_SECRET
created for you.
- Rate limiting: Protect your endpoints with sensible defaults (100 reqs/15min per IP).
- Auth verifier: Middleware to guard protected routes.
- Custom prompts: Choose port, MongoDB base URL, and database name. Trailing slashes are handled automatically.
- Clean architecture:
controllers/
, services/
, models/
, routes/
, middlewares/
folders ready to go.
🚀 Installation
You can install globally or run with npx
:
# Global install
npm install -g node-starter-cli
# Or use npx (no global install required)
npx node-starter-cli <project-name>
💻 Usage
# Scaffold a new project
npx node-starter-cli my-next-api
# Then navigate and start
cd my-next-api
npm run dev
During scaffolding, you'll be prompted for:
- Project name (defaults to your
<project-name>
)
- Port (defaults to
5000
)
- Mongo base URL (defaults to
mongodb://localhost:27017/
)
- Database name (defaults to your project name)
These answers are used to configure:
src/config/db.js
connection string
.env
with PORT
, DB_URL
, JWT_SECRET
, and REFRESH_TOKEN_SECRET
📂 Project Structure
<project-name>/
├── src/
│ ├── config/db.js
│ ├── controllers/authController.js
│ ├── middlewares/
│ │ ├── rateLimiter.js
│ │ └── authVerifier.js
│ ├── models/User.js
│ ├── routes/authRoutes.js
│ ├── services/authService.js
│ └── index.js
├── .env
├── .gitignore
├── package.json
└── README.md
📜 Built‑in Middleware
Rate Limiter (src/middlewares/rateLimiter.js
)
import rateLimit from 'express-rate-limit';
export default rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests
message: { status: 429, error: 'Too many requests, try again later.' }
});
Auth Verifier (src/middlewares/authVerifier.js
)
import jwt from 'jsonwebtoken';
export function authVerifier(req, res, next) {
const token = req.headers.authorization?.split(' ')[1];
if (!token) return res.status(401).json({ error: 'No token provided' });
try {
req.user = jwt.verify(token, process.env.JWT_SECRET);
next();
} catch {
res.status(401).json({ error: 'Invalid or expired token' });
}
}
🤝 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests:
- Fork the repo
- Create your feature branch (
git checkout -b feature/YourFeature
)
- Commit your changes (
git commit -m 'Add YourFeature'
)
- Push to the branch (
git push origin feature/YourFeature
)
- Open a Pull Request
📄 License
This project is licensed under the ISC License — see the LICENSE file for details.