Looking to build a robust Node.js backend without spending hours on boilerplate setup? Meet create-node-dev
, a CLI tool that scaffolds a professional Node.js backend with Express, complete with MongoDB or PostgreSQL support, authentication, security middleware, and optional logging. In this post, we'll explore what create-node-dev
is, its benefits, and how to use it to jumpstart your next project.
What is create-node-dev
?
create-node-dev
is an open-source npm package that automates the creation of a production-ready Node.js backend. It generates a well-organised project structure with Express, pre-configured with essential features like:
- Database Support: Choose between MongoDB (with Mongoose) or PostgreSQL (with Sequelize).
- Authentication: JWT-based authentication for user registration, login, and profile management.
-
Security: Middleware like Helmet for secure headers and
express-rate-limit
for rate limiting. - Logging: Optional Winston logging for console and file output.
- Testing & Linting: Pre-configured with Jest, ESLint, and Prettier.
- Folder Structure: Clean separation of concerns with routes, controllers, models, middleware, and utilities.
Available on npm: create-node-dev
Why Use create-node-dev
?
Benefits
- Saves Time: Skip repetitive setup tasks and get a fully configured backend in minutes.
- Production-Ready: Includes modern best practices for security, error handling, and code organisation.
- Flexible: Supports MongoDB or PostgreSQL, with optional logging to suit your needs.
- Beginner-Friendly: Interactive CLI with arrow key navigation for easy configuration.
- Scalable: Structured for small APIs or large-scale applications, with testing and linting tools included.
Whether you're building a REST API, a microservice, or a full-stack app, create-node-dev
provides a solid foundation to start coding features immediately.
How to Create and Use create-node-dev
Step 1: Installation
Install the package globally using npm to access the CLI:
npx create-node-dev
This command launches an interactive prompt to configure your project.
Step 2: Configure Your Project
The CLI will ask you for:
-
Project name: Name your project folder (default:
node-backend
). -
Use src folder: Organise code in a
src
folder? (y/N). -
Main file name: Specify the main server file (default:
index.js
). - Database: Select MongoDB or PostgreSQL using arrow keys (default: MongoDB).
- Include logging: Enable Winston logging? (y/N).
Example run:
npx create-node-dev
- Enter
my-api
for the project name. - Type
y
for thesrc
folder. - Accept
index.js
as the main file. - Use arrow keys to select
mongodb
. - Type
y
for logging.
The CLI generates a project structure like this:
backend/
├── src/
│ ├── config/
│ │ └── database.js
│ ├── controllers/
│ │ ├── authController.js
│ │ └── userController.js
│ ├── middleware/
│ │ ├── auth.js
│ │ └── errorHandler.js
│ ├── models/
│ │ ├── User.js (MongoDB) or index.js + User.js (PostgreSQL)
│ ├── routes/
│ │ ├── auth.js
│ │ └── users.js
│ ├── services/
│ ├── utils/
│ │ └── logger.js (if logging is enabled)
│ └── index.js
├── logs/ (if logging enabled)
├── .env
├── .gitignore
├── .npmignore
├── package.json
└── README.md
Step 3: Set Up Environment Variables
The generated .env
file includes default configurations. Update it with your database credentials and a secure JWT secret:
Server Configuration
NODE_ENV=development
PORT=3000
JWT Secret
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
Logging (if enabled)
LOG_LEVEL=info
Database Configuration (example for MongoDB)
MONGODB_URI=mongodb://localhost:27017/myApp
OR (example for PostgreSQL)
DB_NAME=my-api
DB_USER=postgres
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
Replace your-super-secret-jwt-key-change-this-in-production
with a secure key and update database credentials as needed.
Step 4: Run the Project
Navigate to your project folder and start the development server:
cd backend
npm run dev
This runs the server with nodemon
, which auto-restarts on file changes. The server will be available at http://localhost:3000
, with a health check endpoint at /health
.
Step 5: Test the API
The backend includes pre-built routes for authentication and user management. Test them using Postman or cURL:
- Health Check:
curl http://localhost:3000/health
Response:
{
"status": "OK",
"message": "Server is running",
"timestamp": "2025-08-01T23:55:00.000Z",
"uptime": 123.456
}
- Register a User:
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"Jane Doe","email":"jane@example.com","password":"securepassword"}'
- Login:
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"jane@example.com","password":"securepassword"}'
Use the returned JWT token to access protected routes like /api/users
.
Step 6: Use Available Scripts
The package.json
includes useful scripts:
-
npm start
: Run in production mode. -
npm run dev
: Run withnodemon
for development. -
npm test
: Run tests with Jest. -
npm run lint
: Lint code with ESLint. -
npm run format
: Format code with Prettier.
Additional Features
- Authentication: Secure JWT-based auth for user management.
- Security: Helmet for HTTP headers and rate-limiting to prevent abuse.
-
Logging: Winston (if enabled) logs to both console and files (
logs/error.log
,logs/combined.log
). - Testing: Jest and Supertest for unit and integration tests.
- Code Quality: ESLint and Prettier for consistent, clean code.
Contributing
create-node-dev
is open-source under the MIT license. Want to contribute? Report issues, suggest features, or submit pull requests on the GitHub repository (replace with actual repo if available).
Conclusion
create-node-dev
is a game-changer for Node.js developers, offering a quick, reliable way to set up a professional backend. Whether you're prototyping a startup idea or building a scalable API, this tool streamlines the process with modern best practices. Try it out and share your experience on npm or in the comments below!
Happy coding! 🚀
Published on August 1, 2025
Top comments (0)