1.1.10 • Published 5 months ago

create-bodhi-node-app v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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:

  1. Start the development server:
npm run dev
  1. 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 šŸŽÆ

  1. Create your API (replace my-project with any name you prefer):
npx create-bodhi-node-app my-project
  1. Install dependencies:
cd my-project
npm install
  1. 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 user
  • POST /api/v1/auth/login - Login user
  • GET /api/v1/auth/me - Get current user profile
  • POST /api/v1/auth/refresh-token - Refresh access token
  • POST /api/v1/auth/forgot-password - Request password reset
  • POST /api/v1/auth/reset-password - Reset password with token
  • POST /api/v1/auth/logout - Logout user

User Management Routes

Regular User Routes:

  • GET /api/v1/users/profile - Get user's profile
  • PUT /api/v1/users/profile - Update user's profile
  • PUT /api/v1/users/password - Update user's password
  • DELETE /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.

1.1.10

5 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago