Skip to content

BODHEESH/create-bodhi-node-app-npm-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Quick Start Tips 🚀

npx create-bodhi-node-app my-api
cd my-api
npm run dev

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published