UNPKG

setup-mern

Version:

A CLI tool to generate a MERN backend boilerplate in seconds!

110 lines (91 loc) β€’ 5.37 kB
# 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.