setup-mern
Version:
A CLI tool to generate a MERN backend boilerplate in seconds!
110 lines (91 loc) β’ 5.37 kB
Markdown
# setup-mern
π A CLI tool to generate a MERN backend boilerplate in seconds!
## Features
- **Complete MERN Backend Boilerplate**: Generates a fully functional folder structure for MERN backend development.
- **Pre-Configured with Best Practices**: Includes essential files and configurations for Express, Mongoose, JWT, error handling, and more.
- **Scalable and Modular**: Designed to be scalable and modular, making it easy to add new features or refactor existing ones.
- **Easy to Use**: No global installation required. Simply use `npx` to generate your boilerplate.
## Installation
No global installation required! Simply use `npx` to generate your boilerplate:
```bash
npx setup-mern my-new-project
```
## Folder Structure and Purpose
Hereβs a detailed explanation of the folder structure generated by `setup-mern`:
```
my-new-project/
βββ src/
β βββ config/ # Configuration files
β β βββ db.js # Database connection setup (Mongoose)
β β βββ envConfig.js # Environment variable configuration (dotenv)
β βββ controllers/ # Controllers for handling request logic
β β βββ authController.js # Authentication-related logic (e.g., login, signup)
β β βββ userController.js # User-related logic (e.g., get user details)
β β βββ postController.js # Post-related logic (e.g., create, update, delete posts)
β βββ middleware/ # Custom middleware
β β βββ authMiddleware.js # Authentication middleware (JWT verification)
β β βββ errorMiddleware.js # Global error handling middleware
β β βββ validationMiddleware.js # Request validation middleware (e.g., Joi, Zod)
β βββ models/ # Database models (Mongoose Schemas)
β β βββ User.js # User model (e.g., name, email, password)
β β βββ Post.js # Post model (e.g., title, content, author)
β βββ routes/ # API routes
β β βββ authRoutes.js # Authentication routes (e.g., /api/v1/auth/login)
β β βββ userRoutes.js # User routes (e.g., /api/v1/users)
β β βββ postRoutes.js # Post routes (e.g., /api/v1/posts)
β βββ services/ # Business logic and service layer
β β βββ authService.js # Authentication service (e.g., login, signup logic)
β β βββ userService.js # User service (e.g., CRUD operations for users)
β β βββ postService.js # Post service (e.g., CRUD operations for posts)
β βββ utils/ # Utility functions and helpers
β β βββ apiFeatures.js # Advanced filtering, sorting, and pagination
β β βββ catchAsync.js # Async error handling wrapper
β β βββ email.js # Email sending utility
β β βββ logger.js # Logging utility (e.g., winston)
β βββ validations/ # Request validation schemas
β β βββ authValidation.js # Validation for authentication routes
β β βββ userValidation.js # Validation for user routes
β β βββ postValidation.js # Validation for post routes
β βββ app.js # Main application setup (Express app, middleware, routes)
β βββ server.js # Server entry point (starts the server)
βββ tests/ # Test files
β βββ unit/ # Unit tests (e.g., testing individual functions)
β βββ integration/ # Integration tests (e.g., testing API endpoints)
β βββ e2e/ # End-to-end tests (e.g., testing the entire application flow)
βββ public/ # Static files (e.g., images, documents)
β βββ uploads/ # Uploaded files (e.g., user profile pictures)
βββ .env # Environment variables (e.g., database URL, JWT secret)
βββ .env.example # Example environment variables file (for documentation)
βββ .gitignore # Files and folders to ignore in Git
βββ .eslintrc.js # ESLint configuration for code linting
βββ .prettierrc # Prettier configuration for code formatting
βββ package.json # Project dependencies and scripts
βββ README.md # Project documentation
βββ Dockerfile # Docker configuration for containerization
```
## Usage
1. **Generate the Boilerplate**:
Run the following command to create a new project:
```bash
npx setup-mern my-new-project
```
2. **Navigate to the Project Folder**:
```bash
cd my-new-project
```
3. **Install Dependencies**:
```bash
npm install
```
4. **Start the Development Server**:
```bash
npm run dev
```
## Documentation
For detailed documentation, visit [setup-mern-docs](#).
## License
Licensed under the MIT License. Copyright Β© 2025 Muhammad Haider.