create-bodhi-node-app v1.1.10
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 install
Using npm global install
First, install the package globally:
npm install -g create-bodhi-node-app
Then create your project and install dependencies:
create-bodhi-node-app my-project
cd my-project
npm install
Getting Started šÆ
After creating your project and installing dependencies:
- Start the development server:
npm run dev
- Or for production:
npm start
Your 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-project
with any name you prefer):
npx create-bodhi-node-app my-project
- Install dependencies:
cd my-project
npm install
- Start development server:
npm run dev
Environment Variables š§
NODE_ENV=development
PORT=3000
MONGODB_URI=mongodb://localhost:27017/your-db-name
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=1d
API 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 functions
Contributing š¤
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.