New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mern-project-cli

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mern-project-cli

A CLI tool to scaffold a MERN stack project

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by225%
Maintainers
1
Weekly downloads
 
Created
Source

MERN Project Generator CLI

Generate a complete MERN stack project with a single command! 🚀

npm npm Node.js Package

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:

  1. Create the complete project structure
  2. Initialize Git repository
  3. Install all dependencies
  4. Set up development scripts

Setting up MongoDB Connection

You have two options for setting up MongoDB connection:

  1. Using Project Name as Database Name:
devcli mongodb-connect

This will create a database named your_project_name_db

  1. Using Custom Database Name:
devcli mongodb-connect -p custom_name
# or
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

  1. Navigate to your new project:

    cd your-project-name
    
  2. Set up the backend:

    cd backend
    cp .env.example .env    # Copy and configure environment variables
    npm run dev            # Start development server with nodemon
    
  3. Set up the frontend (in a new terminal):

    cd frontend
    cp .env.example .env   # Copy and configure environment variables
    npm start             # Start React development server
    
  4. Set up MongoDB:

    devcli mongodb-connect   # From project root or backend directory
    

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   # Start development server with nodemon
npm start     # Start production server

Frontend

npm start     # Start development server
npm build     # Create production 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.

Give ⭐ to the repo mern-project-cli


Made with ❤️ by Manish Raj

Portfolio  GitHub  LinkedIn  Twitter 

Keywords

FAQs

Package last updated on 18 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc