nodejs-boiler
v1.0.0
Published
π A fast, modern, and production-ready Node.js project boilerplate generator CLI. Quickly scaffold a full-featured Express.js application with authentication, database setup, API structure, and best practices.
Maintainers
Readme
π Node.js Boilerplate Generator
A powerful CLI tool to instantly generate production-ready Node.js applications with MongoDB integration. This boilerplate is designed to kickstart your backend development with best practices, security, and scalability in mind.
π― Why This Project?
Building a new Node.js project from scratch involves repetitive setup tasks, configuration, and boilerplate code. This project aims to:
- Save Development Time: Eliminate days of initial setup and configuration
- Enforce Best Practices: Follows industry standards for security, performance, and maintainability
- Scalable Architecture: Built with scalability and maintainability in mind
- Database Flexibility: Seamlessly switch between MongoDB and SQL databases
- Production Ready: Includes essential features like authentication, error handling, and logging
β¨ Features
Core Features
- ποΈ One-command project generation - Get started in seconds
- π Express.js with modern ES modules (ESM)
- π JWT Authentication with role-based access control
- π οΈ Environment-based configuration
- π API documentation with Swagger/OpenAPI
ποΈ MongoDB Features
- Mongoose ODM for elegant MongoDB object modeling
- Schema Validation - Enforce data integrity
- Middleware Support - Pre/post hooks for business logic
- Connection Pooling - Optimized database connections
- Transaction Support - ACID transactions
- Indexing - Optimized query performance
- Aggregation Pipeline - Powerful data processing
SQL Features
- Sequelize ORM for SQL databases
- Support for PostgreSQL, MySQL, SQLite, MSSQL
- Database migrations and seeders
- Connection pooling and transactions
π Getting Started
Prerequisites
- Node.js 16.x or higher
- npm 6.x or higher
Step 1: Install the Boilerplate
Choose one of the following methods:
Method 1: Using npx (Recommended)
# Create a new project
npx nodejs-boilerMethod 2: Global Installation
# Install globally
npm install -g nodejs-boiler
# Create new project
nodejs-boilerStep 2: Verify Installation
Start your application:
# Development mode with hot-reload npm run dev # Or production mode npm start
βοΈ Project configuration
1. Environment Configuration
Create a .env.example file in your project root.
2. Database Connection
Your application automatically connects to database on startup. The connection is managed in src/db folder.
3. Verify the Connection
- Check the console for successful MongoDB connection message
- Check the Api working Visit
http://localhost:8080/ - Visit
http://localhost:8080/healthfor API health status - Access Swagger docs at
http://localhost:8080/api/docs
Quick Start
# Using npx (recommended)
npx nodejs-boiler@latest
# Or install globally
npm install -g nodejs-boiler
nodejs-boiler
# Select a folder:
β― New directory
Current directory
# Project folder Name:
(nodejs_boiler-app) or your_folder_name
# Select a database:
β― mongodb
postgresql
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Start development server
npm run devKey Features of the User Model:
- Schema Validation: Built-in validation for all fields
- Password Hashing: Automatic password hashing before save
- Security: Passwords are not returned by default
- Timestamps: Automatic
createdAtandupdatedAtfields - Role-based Access: User roles with 'user' and 'admin' options
Project Structure π
project-root/
βββ docs/
β βββ swagger.json # All apis swagger json files
|
βββ logs/ # Documentation Folder
|
βββ src/
β βββ configs/ # Configuration files
β β βββ envConfig.js # Application configurations
β β
β βββ controllers/ # Route controllers
β β βββ index.js
β β βββ user.controller.js
β β
β βββ db/ # Database configuration
β β
β βββ helpers/ # Helper functions
β β βββ logger.js
β β βββ mail.js
β β βββ pick.js
β β
β βββ middlewares/ # Express middlewares
β β βββ auth.js
β β βββ schemaValidation.js
β β
β βββ models/ # MongoDB models
β β βββ user.model.js
β β
β βββ routes/ # API routes
β β βββ docs.routes.js
β β βββ index.js
β β βββ user.routes.js
β β
β βββ utils/ # Utility functions
β β βββ message.js
β β βββ responses.js
β β
β βββ validations/ # Request validations
β β βββ index.js
β β βββ user.validation.js
β β
β βββ index.js # Application entry point
β
βββ .env.example # Environment variables example file
βββ .gitignore # Git ignore file
βββ package.json # Project dependencies
βββ README.md # Project documentationπ Best Practices β
Code Style
- Write meaningful commit messages
- Document your code with JSDoc
Security
- Always use environment variables for sensitive data
- Implement proper input validation
- Use parameterized queries to prevent SQL injection
- Implement rate limiting and CORS
Performance
- Use database indexing for frequently queried fields
- Implement caching where appropriate
- Optimize database queries
- Use connection pooling for database connections
π€ Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
Author π¨βπ»
- Ajay Dumaraliya - GitHub
π Support
If you find this project helpful, please consider giving it a βοΈ on GitHub.
