manishraj27 / mern-project-cli

A developer-friendly CLI tool that streamlines MERN stack development by automating project setup, database configuration, and boilerplate generation by implementing MVC Architecture. Create production-ready MongoDB, Express, React, and Node.js applications with best practices built-in
https://devcli.vercel.app
MIT License
7 stars 2 forks source link
cli collaborate github github-codespaces mern-project-cli mern-stack node npm

🚀 MERN Project Generator CLI

Create production-ready MERN stack projects in seconds!

Website https://devcli.vercel.app

NPM Weekly Downloads NPM Total Downloads Node.js Package

Are you tired of:

MERN Project Generator CLI is your ultimate solution! In just seconds, create a complete, production-ready MongoDB, Express, React, and Node.js project structure with a single command.

✨ Features

📑 Index

⚡ Requirements

Before you begin, ensure your system meets these requirements:

📦 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

🛠️ Commands

1. Create MERN Project

devcli create <your_project_name>

What This Command Does:

1. 📁 Creates Project Structure:

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
2. Installs Dependencies:

After Creation:

Start Backend Development:
cd your-project-name/backend
npm run dev             # Start development server with nodemon
Start Frontend Development:
cd your-project-name/frontend
npm start               # Start React App

2. Connect MongoDB

Options:

What This Command Does:

1. Creates Database Connection:
2. Updates Server Configuration:

Usage Examples:

# Using project name
devcli mongodb-connect

# Using custom database name
devcli mongodb-connect --project custom_name

Generated Files:

// 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));

3. Generate Mongoose Schema

Example
```bash
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;

Explanation:

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.

📖 Complete User Journey Example

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

⚙️ Environment Configuration

Backend (.env)

# Server Configuration
PORT=5000

# Database Configuration
DB_URI=mongodb://localhost:27017/your_db_name

Frontend (.env)

# API Configuration
REACT_APP_API_URL=http://localhost:5000

🔧 Development Commands

Backend Commands

npm run dev     # Start with auto-reload (development)
npm start       # Start without auto-reload (production)

Frontend Commands

npm start       # Start development server
npm run build   # Create production build
npm test        # Run tests
npm run eject   # Eject from Create React App

Why Choose MERN Project Generator CLI?

🎯 Perfect For:

💪 Built for Real Development:

🛠️ What You Get:

Skip the boring setup and jump straight into building your next big idea! Whether you're creating a quick prototype, starting a serious project, or learning the MERN stack, this CLI tool gives you the perfect foundation to build upon.

🔮 Future Enhancements

  1. Code Generation

    • API route generator
    • React component generator
    • CRUD operations generator
  2. Template System

    • Custom template support

🤝 Contribute to the Project

We welcome and appreciate contributions to MERN Project Generator CLI! If you’d like to help improve this tool, feel free to:

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🌟 Support the Project

If you find this tool helpful, please consider:

🌟 Made with ❤️ by Manish Raj

PortfolioGitHubLinkedInTwitter