MERN Project Generator CLI
Generate a complete MERN stack project with a single command! 🚀
MERN Project Generator CLI is a powerful command-line tool designed to jumpstart your MERN (MongoDB, Express, React, Node.js) stack projects. With just one command, you can scaffold a complete project structure for both backend and frontend, following best practices and including essential configurations.
Key Features
- Full MERN Stack Setup: Generate both backend and frontend projects in one go.
- Best Practices Built-in: The generated projects follow industry-standard best practices for MERN stack development.
- Dynamic MongoDB Integration: Easily set up MongoDB connection with automatic database naming.
- Customizable Database Names: Flexibility to use custom database names or automatic project-based naming.
- Environment Ready: Includes pre-configured
.env.example
files for both frontend and backend. - Development Mode: Built-in development server configuration with nodemon.
- Instant Development Ready: Start coding your application logic immediately after generation.
Requirements
- Node.js 14.x or higher
- npm 6.x or higher
- MongoDB (local or remote)
Installation
Install the CLI globally using npm:
npm install -g mern-project-cli
Available Commands
Check all available commands and options:
devcli --help
This will show you:
Usage: devcli [options] [command]
A CLI tool to scaffold and manage MERN stack projects
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
create <projectName> Create a new MERN project
mongodb-connect [options] Generate MongoDB connection code
help [command] display help for command
Creating a New Project
Create a new MERN project:
devcli create your-project-name
This will:
- Create the complete project structure
- Initialize Git repository
- Install all dependencies
- Set up development scripts
Setting up MongoDB Connection
You have two options for setting up MongoDB connection:
- Using Project Name as Database Name:
devcli mongodb-connect
This will create a database named your_project_name_db
- Using Custom Database Name:
devcli mongodb-connect -p custom_name
devcli mongodb-connect --project custom_name
This will create a database named custom_name_db
Generated Project Structure
your-project-name/
├── backend/
│ ├── controllers/
│ ├── db/
│ │ └── connection.js # MongoDB connection configuration
│ ├── middlewares/
│ ├── models/
│ ├── routes/
│ ├── utils/
│ ├── .env.example # DB_URL=mongodb://localhost:27017/your_db
│ ├── .gitignore # Includes node_modules, .env, etc.
│ ├── constants.js
│ ├── package.json # Includes express, mongoose, dotenv, etc.
│ ├── README.md
│ └── server.js # Express server with MongoDB connection
└── frontend/
├── public/
├── src/
├── .env.example # REACT_APP_API_URL=http://localhost:5000/api
├── package.json
└── README.md
Getting Started After Generation
-
Navigate to your new project:
cd your-project-name
-
Set up the backend:
cd backend
cp .env.example .env
npm run dev
-
Set up the frontend (in a new terminal):
cd frontend
cp .env.example .env
npm start
-
Set up MongoDB:
devcli mongodb-connect
Environment Variables
Backend (.env)
PORT=5000
DB_URL=mongodb://localhost:27017/your_project_db # Default if not specified
Frontend (.env)
REACT_APP_API_URL=http://localhost:5000/api
Development Scripts
Backend
npm run dev
npm start
Frontend
npm start
npm build
Customization
The generated structure is designed to be easily customizable:
- Controllers: Add your API logic in
backend/controllers/
- Models: Define MongoDB schemas in
backend/models/
- Routes: Add API routes in
backend/routes/
- Middlewares: Add custom middlewares in
backend/middlewares/
- Frontend Components: Add React components in
frontend/src/components/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.