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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-mod-cli

v1.1.2

Published

Modern Express.js application generator with clean MVC architecture and Mongoose ODM integration. Install globally using 'npm install -g express-mod-cli'

Readme

Express Modular Generator

A modern command-line tool to generate Express.js applications with clean MVC architecture and Mongoose ODM integration.

✨ Features

  • 🏗️ Modular MVC Architecture - Clean separation of concerns
  • 🍃 Mongoose Integration - Modern MongoDB ODM with schema validation
  • 🚀 Latest Dependencies - Express 5.x, Mongoose 8.x, and more
  • 🔒 Security Ready - CORS, Helmet, and error handling built-in
  • Zero Configuration - Ready to run with minimal setup
  • 📦 Modular Design - Easy to add and manage modules

📋 Installation

npm install -g express-mod-cli

🚀 Quick Start

Create a new project

express-mod-cli create my-project
cd my-project
npm run dev

Add modules to your project

express-mod-cli add users
express-mod-cli add products
express-mod-cli add orders

📖 Commands

| Command | Description | Example | | ----------------------- | ----------------------------------- | ------------------------------- | | create <project-name> | Create a new Express project | express-mod-cli create my-app | | add <module-name> | Add a new module to current project | express-mod-cli add users | | --help or -h | Show help information | express-mod-cli --help | | --version or -v | Show version number | express-mod-cli --version |

🗄️ Database Configuration

MongoDB with Mongoose

Your generated project uses Mongoose for elegant MongoDB object modeling. The configuration is already set up in src/config/db.js.

Local MongoDB Setup

  1. Install MongoDB locally or use Docker:

    # Using Docker
    docker run -d -p 27017:27017 --name mongodb mongo:latest
  2. Update your .env file:

    MONGODB_URI=mongodb://localhost:27017
    DB_NAME=your_project_name_db
    PORT=5000
    NODE_ENV=development

MongoDB Atlas Setup (Cloud)

  1. Create a MongoDB Atlas account at mongodb.com/atlas
  2. Get your connection string from Atlas dashboard
  3. Update your .env file:
    MONGODB_URI=mongodb+srv://username:[email protected]
    DB_NAME=your_project_name_db
    PORT=5000
    NODE_ENV=production

🏗️ Generated Project Structure

Each generated project follows this clean structure:

my-project/
├── src/
│   ├── config/
│   │   └── db.js                 # Mongoose connection setup
│   ├── middleware/
│   │   └── errorHandler.js       # Global error handling
│   ├── modules/                  # Your business modules
│   │   └── [module-name]/
│   │       ├── module.model.js   # Mongoose schema & model
│   │       ├── module.controller.js # Business logic
│   │       └── module.routes.js  # Express routes
│   ├── utils/                    # Utility functions
│   └── index.js                  # Main server file
├── .env                          # Environment variables
├── .gitignore                    # Git ignore rules
└── package.json                  # Dependencies & scripts

📦 Module Architecture

Each module generates exactly 3 files following MVC pattern:

🔹 Model ({module}.model.js)

const mongoose = require("mongoose");

const userSchema = new mongoose.Schema(
  {
    name: { type: String, required: true, trim: true },
    description: { type: String, trim: true },
    status: {
      type: String,
      enum: ["active", "inactive"],
      default: "active",
    },
  },
  { timestamps: true }
);

module.exports = mongoose.model("User", userSchema);

🔹 Controller ({module}.controller.js)

const User = require("./user.model");

async function getAll(req, res, next) {
  try {
    const items = await User.find().sort({ createdAt: -1 });
    res.json({
      success: true,
      data: items,
      message: "Users retrieved successfully",
    });
  } catch (error) {
    next(error);
  }
}
// ... other CRUD methods

🔹 Routes ({module}.routes.js)

const express = require("express");
const router = express.Router();
const userController = require("./user.controller");

router.get("/", userController.getAll);
router.get("/:id", userController.getById);
router.post("/", userController.create);
router.patch("/:id", userController.update);
router.delete("/:id", userController.remove);

module.exports = router;

🔗 API Endpoints

Each generated module provides RESTful API endpoints:

| Method | Endpoint | Description | Response | | -------- | --------------- | --------------- | ------------------------------------------------ | | GET | /{module} | Get all items | { success: true, data: [...], message: "..." } | | GET | /{module}/:id | Get one item | { success: true, data: {...}, message: "..." } | | POST | /{module} | Create new item | { success: true, data: {...}, message: "..." } | | PATCH | /{module}/:id | Update item | { success: true, data: {...}, message: "..." } | | DELETE | /{module}/:id | Delete item | { success: true, data: {...}, message: "..." } |

🔍 Example API Usage

# Get all users
curl http://localhost:5000/users

# Get specific user
curl http://localhost:5000/users/60d5ec49f1b2c8b1f8e4e1a1

# Create new user
curl -X POST http://localhost:5000/users \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "description": "Software Developer"}'

# Update user
curl -X PATCH http://localhost:5000/users/60d5ec49f1b2c8b1f8e4e1a1 \
  -H "Content-Type: application/json" \
  -d '{"status": "inactive"}'

🛠️ Technology Stack

Core Dependencies

  • Express.js 5.x - Fast, unopinionated web framework
  • Mongoose 8.x - Elegant MongoDB object modeling
  • dotenv 17.x - Environment variable management
  • CORS 2.x - Cross-origin resource sharing
  • Helmet 8.x - Security middleware

Development Dependencies

  • Nodemon 3.x - Development server with auto-restart

🏃‍♂️ Development Workflow

  1. Create Project:

    express-mod-cli create my-ecommerce-app
    cd my-ecommerce-app
  2. Configure Database:

    # Edit .env file
    MONGODB_URI=mongodb://localhost:27017
    DB_NAME=ecommerce_db
  3. Add Business Modules:

    express-mod-cli add products
    express-mod-cli add categories
    express-mod-cli add orders
    express-mod-cli add customers
  4. Start Development:

    npm run dev

🎯 Best Practices

Model Customization

After generating a module, customize the Mongoose schema:

// Example: Enhanced User model
const userSchema = new mongoose.Schema(
  {
    name: { type: String, required: true, trim: true },
    email: { type: String, required: true, unique: true },
    password: { type: String, required: true, minlength: 6 },
    role: { type: String, enum: ["user", "admin"], default: "user" },
    profile: {
      avatar: String,
      bio: String,
      phone: String,
    },
  },
  { timestamps: true }
);

Controller Enhancement

Add business logic to controllers:

// Add custom methods
async function getUserByEmail(req, res, next) {
  try {
    const user = await User.findOne({ email: req.params.email });
    // ... handle response
  } catch (error) {
    next(error);
  }
}

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 Changelog

v1.1.0 (Latest)

  • 🆕 Mongoose Integration - Replaced native MongoDB driver with Mongoose ODM
  • 🔄 Modular CLI Architecture - Refactored CLI into clean, maintainable modules
  • ⬆️ Updated Dependencies - Latest versions (Express 5.x, Mongoose 8.x)
  • 🐛 Bug Fixes - Resolved template generation issues
  • 📚 Enhanced Documentation - Complete API reference and examples
  • 🔒 Security Improvements - Zero vulnerabilities in generated projects

v1.0.11 (Previous)

  • Basic project and module generation
  • Native MongoDB driver integration
  • Simple MVC structure

📞 Support

📜 License

MIT © Nizam Uddin


Made with ❤️ for the Express.js community