Skip to content

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

License

Notifications You must be signed in to change notification settings

rsnj5/mern-project-cli

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

43 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ MERN Project Generator CLI

Create production-ready MERN stack projects in seconds!

NPM Package Website mern-project-cli

NPM Weekly Downloads NPM Total Downloads Node.js Package

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.

โœจ Features

  • 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

๐Ÿ“‘ Index

โšก Requirements

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

๐Ÿ“ฆ 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:
  • Backend:
    • Express
    • Mongoose
    • CORS
    • dotenv
    • nodemon (dev dependency)
  • Frontend:
    • React
    • React Router
    • Axios
    • Other Create React App 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

  • Create database as your_project_name_db
devcli mongodb-connect
  • Or with custom database name
devcli mongodb-connect --project custom-name  

Options:

  • -p, --project <name>: Specify custom database name
  • No options: Uses project folder name as database name

What This Command Does:

1. Creates Database Connection:
  • Generates connection.js in the db folder
  • Sets up Mongoose connection with error handling
  • Configures connection string based on environment variables
2. Updates Server Configuration:
  • Adds database connection import to server.js
  • Sets up connection status logging

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

  • 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;

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

๐Ÿ”ฎ Future Enhancements

  1. Code Generation
    • More Code-Snippets

๐Ÿค 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 do so.

๐Ÿ“„ 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:

  • Giving it a star on GitHub
  • View on NPM mern-project-cli
  • Sharing it with your fellow developers
  • Contributing to its development

๐ŸŒŸ Made with โค๏ธ by Manish Raj

Portfolio โ€ข GitHub โ€ข LinkedIn โ€ข Twitter

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%