create-bodhi-node-app
v1.1.10
Published
Create production-ready Node.js REST APIs with zero configuration - Authentication, MongoDB, Error Handling, and more!
Maintainers
Readme
Create Bodhi Node App
Create production-ready Node.js REST APIs with zero configuration. Get started with a fully-featured Express.js application in seconds.
Installation 🚀
You can create a new app using either of these methods:
Using npx (recommended)
npx create-bodhi-node-app my-project
cd my-project
npm installUsing npm global install
First, install the package globally:
npm install -g create-bodhi-node-appThen create your project and install dependencies:
create-bodhi-node-app my-project
cd my-project
npm installGetting Started 🎯
After creating your project and installing dependencies:
- Start the development server:
npm run dev- Or for production:
npm startYour API will be running at http://localhost:3000
Features Included 🌟
- Express.js setup with best practices
- MongoDB integration with Mongoose
- Authentication with JWT
- Request validation using Zod
- Error handling middleware
- Logging with Winston and Morgan
- Security with Helmet and CORS
- API compression
- ESLint and Prettier configuration
- Development mode with Nodemon
Why Bodhi Node App? 🤔
While frontend developers have had tools like create-react-app for years, backend developers have been left to configure their Node.js applications from scratch. Bodhi Node App changes that by providing a production-ready Node.js REST API boilerplate with all the essential features you need.
Getting Started In Detail 🎯
- Create your API (replace
my-projectwith any name you prefer):
npx create-bodhi-node-app my-project- Install dependencies:
cd my-project
npm install- Start development server:
npm run devEnvironment Variables 🔧
NODE_ENV=development
PORT=3000
MONGODB_URI=mongodb://localhost:27017/your-db-name
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=1dAPI Endpoints 🔌
Authentication Routes
POST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- Login userGET /api/v1/auth/me- Get current user profilePOST /api/v1/auth/refresh-token- Refresh access tokenPOST /api/v1/auth/forgot-password- Request password resetPOST /api/v1/auth/reset-password- Reset password with tokenPOST /api/v1/auth/logout- Logout user
User Management Routes
Regular User Routes:
GET /api/v1/users/profile- Get user's profilePUT /api/v1/users/profile- Update user's profilePUT /api/v1/users/password- Update user's passwordDELETE /api/v1/users/account- Delete user's account
Admin Routes (Requires admin role):
GET /api/v1/users/admin- Get all users (admin only)GET /api/v1/users/admin/:id- Get specific user (admin only)PUT /api/v1/users/admin/:id/role- Update user's role (admin only)
API Documentation
All endpoints are documented using Swagger/OpenAPI specification and include:
- Request/Response schemas
- Authentication requirements
- Validation rules
- Error responses
- Example payloads
Access the full API documentation by visiting /api-docs after starting your server.
Route Protection
- All user management routes are protected with JWT authentication
- Admin routes have additional role-based authorization
- Input validation using Zod schema validation
- Rate limiting to prevent abuse
- CORS protection configured
Features in Detail 🌟
Authentication & Authorization 🔐
- JWT-based Authentication: Secure token-based authentication system
- Role-Based Access Control: Easily manage user permissions
- Password Reset Flow: Complete forgot/reset password functionality
- Token Refresh: Automatic access token refresh mechanism
- Secure Password Handling: bcrypt hashing for passwords
Database Integration 🗄️
- MongoDB & Mongoose: Ready-to-use MongoDB integration with Mongoose ODM
- Schema Validation: Mongoose schemas with built-in validation
- Index Management: Optimized database indexes
- Soft Delete: Built-in support for soft deletion
Security Features 🛡️
- Helmet Integration: Secure HTTP headers automatically configured
- CORS Protection: Configurable CORS settings
- Rate Limiting: Protect your API from abuse
- XSS Protection: Cross-site scripting protection
- SQL Injection Protection: Query sanitization
- Parameter Pollution Protection: Prevent parameter pollution attacks
Request Validation ✅
- Zod Integration: Type-safe request validation
- Custom Validators: Easy to add custom validation rules
- Validation Middleware: Pre-built validation middlewares
- Error Messages: Clear, customizable error messages
Error Handling 🚨
- Centralized Error Handling: Global error handling middleware
- Custom Error Classes: Specific error types for different scenarios
- Operational vs Programming Errors: Different handling for different error types
- Error Logging: Automatic error logging with stack traces
Logging System 📝
- Winston Logger: Advanced logging with Winston
- Multiple Transports: Console and file logging
- Log Levels: Different log levels for development and production
- Request Logging: Morgan integration for HTTP request logging
API Documentation 📚
- Swagger/OpenAPI: Automatic API documentation
- API Versioning: Built-in support for API versioning
- Request/Response Examples: Clear examples in documentation
- Authentication Documentation: Security schemes documentation
Development Tools 🛠️
- Hot Reloading: Automatic server restart with Nodemon
- ESLint Configuration: Code linting with ESLint
- Prettier Integration: Consistent code formatting
- Git Setup: Pre-configured .gitignore
- Environment Variables: Dotenv configuration
Performance Optimizations 🚄
- Compression: Gzip compression enabled
- Security Headers: Optimized security headers
- Body Parsing: Efficient request body parsing
- Error Handling: Performance-optimized error handling
Project Structure 📁
Follows industry best practices with a clean, maintainable structure:
src/
├── config/ # Environment variables & configuration
├── controllers/ # Route controllers (controller layer)
├── middleware/ # Custom express middlewares
├── models/ # Mongoose models (data layer)
├── routes/ # Routes
└── utils/ # Utility classes and functionsContributing 🤝
Contributions are welcome! Please feel free to submit a Pull Request.
License 📄
This project is licensed under the MIT License - see the LICENSE file for details.
A Note from the Creator 💭
Just as frontend developers have create-react-app to jumpstart their React projects, backend developers deserve a robust solution for Node.js applications. That's why I created Bodhi Node App - to provide backend developers with a production-ready, feature-rich foundation for their REST APIs.
No more spending hours on boilerplate code or worrying about security configurations. With Bodhi Node App, you get a professionally structured Node.js application with all the essential features you need to build secure, scalable APIs.
Created with ❤️ by Bodheesh
Support 🌟
If you find this project helpful, please give it a star ⭐ on GitHub! It helps more developers discover this tool.
