npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mern-project-cli

v2.0.0

Published

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 applicatio

Downloads

318

Readme

🚀 MERN Project Generator CLI

Create production-ready MERN stack projects in seconds!

NPM Weekly Downloads NPM Total Downloads Node.js Package

Are you tired of:

  • ⏰ Spending hours setting up basic MERN project structures?
  • 🔧 Configuring MongoDB connections from scratch?
  • 📁 Creating the same folder structure over and over?
  • 🎯 Missing important configurations in your initial setup?
  • 🔄 Copying boilerplate code from old projects?

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

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

    • Check with: node --version
    • Download from: nodejs.org
  • npm: Version 6.x or higher

    • Check with: npm --version
    • Comes with Node.js installation
  • 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));

📖 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

🎉 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:

  • Startups: Launch MVPs faster with a solid foundation
  • Freelancers: Start client projects instantly
  • Teams: Maintain consistent project structure across developers
  • Learning: Focus on coding instead of setup when learning MERN stack
  • Hackathons: Get your project up and running in minutes

💪 Built for Real Development:

  • Production-Ready: Follows industry best practices out of the box
  • Scalable Structure: Organized for growth from day one
  • Developer Friendly: Hot-reloading, environment configs, and Git ready
  • Customizable: Easy to modify and extend based on your needs
  • Time-Saving: Eliminate repetitive setup tasks

🛠️ What You Get:

  • Complete MERN Setup: MongoDB, Express, React, and Node.js configured and ready
  • Modern Tooling: Latest versions of all dependencies
  • Development Mode: Hot-reloading for both frontend and backend
  • API Ready: Basic API structure with examples
  • Database Connected: MongoDB configuration with just one command
  • Environment Ready: Pre-configured environment files
  • Version Control: Git initialized with proper .gitignore files

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

    • Database schema generator
    • 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:

  • Fork the repository
  • Submit pull requests
  • Open issues for bugs or suggestions Your contributions will help make this tool even better for the developer community!

📄 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
  • Sharing it with your fellow developers
  • Contributing to its development