npm.io
1.1.0 • Published 20h agoCLI

setup-mern

Licence
MIT
Version
1.1.0
Deps
4
Size
267 kB
Vulns
0
Weekly
11

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:

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:

    npx setup-mern my-new-project
  2. Navigate to the Project Folder:

    cd my-new-project
  3. Install Dependencies:

    npm install
  4. Start the Development Server:

    npm run dev

Documentation

For detailed documentation, visit setup-mern-docs.


License

Licensed under the MIT License. Copyright 2026 Muhammad Haider.

Keywords