UNPKG

express-mongo-boilerplate-generator

Version:

A production-ready boilerplate generator for Express.js and MongoDB with service layer architecture and Joi validation

154 lines (111 loc) • 3.92 kB
# Express MongoDB Boilerplate Generator A powerful CLI tool to generate production-ready Express.js and MongoDB applications with service layer architecture, Joi validation, and industry best practices. ## šŸš€ Installation ```bash npm install -g express-mongo-boilerplate-generator ``` Or use with npx (recommended): ```bash npx express-mongo-boilerplate-generator create my-app ``` ## ⚔ Quick Start ### Create a new project: ```bash create-express-mongo-app create my-awesome-api ``` ### Interactive mode: ```bash create-express-mongo-app init ``` ## ✨ Features - āœ… **Service Layer Architecture** - Clean separation of concerns - āœ… **Joi Validation** - Robust request validation - āœ… **JWT Authentication** - Secure token-based auth - āœ… **MongoDB with Mongoose** - Modern ODM - āœ… **Organized Enums** - Centralized constants - āœ… **Error Handling** - Custom error classes - āœ… **Docker Support** - Ready for containerization - āœ… **Testing Setup** - Jest with in-memory MongoDB - āœ… **ESLint & Prettier** - Code quality tools - āœ… **Security** - Helmet, CORS, Rate limiting ## šŸ“ Generated Project Structure ``` my-app/ ā”œā”€ā”€ src/ │ ā”œā”€ā”€ controllers/ # HTTP request handlers │ ā”œā”€ā”€ services/ # Business logic layer │ ā”œā”€ā”€ routes/ # API endpoints │ ā”œā”€ā”€ models/ # Mongoose schemas │ ā”œā”€ā”€ validators/ # Joi validation schemas │ ā”œā”€ā”€ middleware/ # Custom middleware │ ā”œā”€ā”€ utils/ │ │ └── enums/ # Enum constants │ ā”œā”€ā”€ app.js # Express app setup │ └── server.js # Server entry point ā”œā”€ā”€ __tests__/ # Test files ā”œā”€ā”€ .env # Environment variables ā”œā”€ā”€ .env.example # Environment template ā”œā”€ā”€ docker-compose.yml # Docker compose config ā”œā”€ā”€ Dockerfile # Docker configuration ā”œā”€ā”€ package.json └── README.md ``` ## šŸ› ļø CLI Options ```bash create-express-mongo-app create <project-name> [options] Options: -g, --git Initialize git repository -i, --install Install dependencies automatically -h, --help Display help -V, --version Output version number ``` ## šŸ“‹ Requirements - Node.js >= 14.0.0 - npm >= 6.0.0 - MongoDB (local or Atlas) ## šŸ—ļø Architecture The generated boilerplate follows **Service Layer Architecture**: - **Routes** → Define endpoints - **Controllers** → Handle HTTP only - **Services** → Business logic & DB operations - **Validators** → Joi request validation - **Models** → Mongoose schemas - **Enums** → Centralized constants ## šŸ”§ Usage Example After generating your project: ```bash # Navigate to project cd my-awesome-api # Install dependencies npm install # Set up environment variables cp .env.example .env # Start development server npm run dev ``` Your API will be running at `http://localhost:3000` ## 🌟 What's Included - User authentication system - JWT token management - Request validation with Joi - Error handling middleware - MongoDB connection management - Pagination support - Security best practices - Docker configuration - Testing setup - ESLint configuration ## šŸ“ License MIT ## šŸ‘Øā€šŸ’» Author **Usama Talib** - Email: talibusama1234@gmail.com - GitHub: [@usamatalib](https://github.com/Usama123talib) ## šŸ¤ Contributing Issues and pull requests are welcome! ## šŸ”— Links - [GitHub Repository](https://github.com/Usama123talib/express-mongo-boilerplate) - [NPM Package](https://www.npmjs.com/package/express-mongo-boilerplate-generator) - [Report Issues](https://github.com/Usama123talib/express-mongo-boilerplate/issues) --- Made with ā¤ļø by Usama Talib