![](https://private-user-images.githubusercontent.com/110532770/361422672-1226438f-19e0-46e4-beff-5483e429ee69.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MTkxNTgsIm5iZiI6MTczOTUxODg1OCwicGF0aCI6Ii8xMTA1MzI3NzAvMzYxNDIyNjcyLTEyMjY0MzhmLTE5ZTAtNDZlNC1iZWZmLTU0ODNlNDI5ZWU2OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQwNzQwNThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wYmMyMWIxNmI0ZGRlNjk4MTVjNTdkYTQzMDdiMjI2NWI2NzI1ZWMzNDk1MzE3ZDliYzY2ZWFlZDk0MGU1YTMzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.diZVEck5zgJmhV37rLHPyUmMXXUfWsuhZxoG-iILJO4)
Create production-ready MERN stack projects in seconds!
NPM Package Website mern-project-cli
Website https://devcli.vercel.app
MERN Project Generator CLI is a powerful tool designed to simplify the process of setting up a complete, production-ready MERN stack project in seconds.
This tool eliminates the need for manual configurations, boilerplate code copying, and repetitive tasks, allowing developers to start building their apps right away with best practices in place. Perfect for both beginners and experienced developers, it saves time and ensures a solid project foundation.
- One Command Setup: Generate both frontend and backend with a single command
- Industry-Standard Structure: Pre-configured folder structure following best practices
- Instant MongoDB Integration: Connect to MongoDB with zero configuration
- Generate Mongoose Schema: Generate Mongoose Schema with just one command
- Development Ready: Hot-reloading enabled for both frontend and backend
- Pre-configured Environment:
.env.example
files included with sensible defaults - Git Ready: Initialized Git repository with proper
.gitignore
files
- Requirements
- Installation
- Commands
- Complete User Journey Example
- Future Enhancements
- Contribute
- License
- Support the project
Before you begin, ensure your system meets these requirements:
- Node.js: Version 14.x or higher
- npm: Version 6.x or higher
- MongoDB: Local or remote installation
Install the CLI tool globally to use it from anywhere in your system:
npm install -g mern-project-cli
To check installation version:
devcli --version
devcli create <your_project_name>
The generated project follows the MVC (Model-View-Controller) pattern, a battle-tested architecture that separates your application into three main components:
your-project-name/
โโโ backend/
โ โโโ controllers/ # Handle business logicdocumentation
โ โโโ db/ # Database configuration
โ โโโ middlewares/ # Custom middleware functionsdocumentation
โ โโโ models/ # MongoDB Schema model
โ โโโ routes/ # API route definitions
โ โโโ utils/ # Helper functionsdocumentation
โ โโโ .env.example # Environment variables template
โ โโโ .gitignore # Git ignore rules
โ โโโ constants.js # Application constants
โ โโโ package.json # Dependencies and scripts
โ โโโ README.md # Backend documentation
โ โโโ server.js # Server entry point
โโโ frontend/
โโโ public/ # Static files
โโโ src/ # React source code
โ โโโ components/ # React components
โ โโโ pages/ # Page components
โ โโโ utils/ # Helper functions
โ โโโ App.js # Root component
โโโ .env.example # Frontend environment template
โโโ package.json # Frontend dependencies
- Backend:
- Express
- Mongoose
- CORS
- dotenv
- nodemon (dev dependency)
- Frontend:
- React
- React Router
- Axios
- Other Create React App dependencies
cd your-project-name/backend
npm run dev # Start development server with nodemon
cd your-project-name/frontend
npm start # Start React App
- Create database as your_project_name_db
devcli mongodb-connect
- Or with custom database name
devcli mongodb-connect --project custom-name
-p, --project <name>
: Specify custom database name- No options: Uses project folder name as database name
- Generates
connection.js
in thedb
folder - Sets up Mongoose connection with error handling
- Configures connection string based on environment variables
- Adds database connection import to
server.js
- Sets up connection status logging
# Using project name
devcli mongodb-connect
# Using custom database name
devcli mongodb-connect --project custom_name
// db/connection.js
require('dotenv').config();
const mongoose = require('mongoose');
const dburl = process.env.DB_URL || "mongodb://localhost:27017/your_db_name";
mongoose.connect(dburl)
.then(() => console.log("Connected to DB Successfully"))
.catch((err) => console.log(err.message));
- Create mongoose schema for your backend.
devcli devcli mongoose-schema <schema-name> <fieldName:fieldType fieldName:fieldType ...>
Example
devcli mongoose-schema User name:String email:String password:String
This will create a User.js
file with a Mongoose schema inside the models/
directory:
//models/User.js
import mongoose from 'mongoose';
const UserSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true },
password: { type: String, required: true }
});
const User = mongoose.model('User', UserSchema);
export default User;
The mongoose-schema
command takes a model name (User) and field definitions (name:String, email:String, password:String), generating a Mongoose model file in the models/
folder.
Let's create a blog application from scratch:
# Step 1: Install CLI globally
npm install -g mern-project-cli
# Step 2: Create new project
devcli create my-blog-app
# Step 3: Set up backend
cd my-blog-app/backend
npm run dev
# Step 4: Set up frontend (new terminal)
cd ../frontend
npm start
# Step 5: Connect MongoDB (optional)
cd ../backend
devcli mongodb-connect
# Step 6: Generate Mongoose Scheama (optional)
devcli mongoose-schema Blog name:String category:String
๐ Congratulations! Your blog application structure is ready with:
- Backend running on `http://localhost:5000`
- Frontend running on `http://localhost:3000`
- MongoDB connected and ready to use
# Server Configuration
PORT=5000
# Database Configuration
DB_URI=mongodb://localhost:27017/your_db_name
# API Configuration
REACT_APP_API_URL=http://localhost:5000
npm run dev # Start with auto-reload (development)
npm start # Start without auto-reload (production)
npm start # Start development server
npm run build # Create production build
npm test # Run tests
npm run eject # Eject from Create React App
- Code Generation
- More Code-Snippets
We welcome and appreciate contributions to MERN Project Generator CLI! If youโd like to help improve this tool, feel free to do so.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this tool helpful, please consider:
- Giving it a star on GitHub
- View on NPM mern-project-cli
- Sharing it with your fellow developers
- Contributing to its development