exp-mvc
v1.2.0
Published
Generate a new ExpressJS project in MVC architecture using command line interface (CLI) and auto-dependency installation.
Maintainers
Readme
exp-mvc
Node.js Express project generator that instantly creates a clean, scalable, and production-ready folder structure based on the MVC architecture. Includes powerful CLI commands to generate controllers, models, routes, and complete CRUD scaffolds with auto-dependency installation.
Designed for developers who want to skip boilerplate setup and start building features immediately.
Install
npm install -g exp-mvcAfter installing exp-mvc globally , run the following command:
expmvc new myappOr
npx exp-mvc new myappThis will create:
./myappwith the full project structure.
Navigate to the project folder:
cd myappInside your project folder, install dependencies:
npm installconfigure the mongodb connection in the .env file
MONGODB_URI=mongodb://localhost:27017/myappRun the server:
npm startor
npm run devRun the watch command to automatically install dependencies on file save:
npm run watchOpen the browser at http://localhost:3000
🔥 CLI Commands Reference
Once inside your generated project, use the expmvc command to generate components:
Generate Complete CRUD Scaffold
Create a full CRUD module with controller, model, service, route, and validation files:
expmvc generate scaffold User name:string email:string password:string age:numberGenerate Individual Components
Generate a controller
expmvc generate controller ProductGenerate a model with fields
expmvc generate model Category name:string description:stringGenerate a route
expmvc generate route OrderGenerate a service
expmvc generate service AuthGenerate a validation file
expmvc generate validation UserGenerate a view (EJS template)
expmvc generate view home/indexCommand Aliases
'g' is alias for 'generate'
'expmvc g scaffold User name:string email:string'
Short forms
expmvc g c User # controllerexpmvc g m User # modelexpmvc g r User # routeexpmvc g s User # serviceexpmvc g v User # validationRelations Between Models
1. Generate Individual Models with References:
# Generate User model
expmvc generate model User name:string email:string password:string
# Generate Post model with User reference
expmvc generate model Post title:string content:string user:ref:User
# Generate Comment model with User and Post references
expmvc generate model Comment content:string user:ref:User post:ref:Post2. Create Relationships Between Existing Models:
# Add belongsTo relationship from Post to User
expmvc rel belongsTo Post User --field author
# Add hasMany relationship from User to Post
expmvc rel hasMany User Post --field posts
# Add belongsToMany relationship (for tags, categories, etc.)
expmvc rel belongsToMany Post Tag --field tags[]3. Complete Relationship Scaffold:
# Scaffold User-Post relationship (One-to-Many)
expmvc sr User Post hasMany
# Scaffold Post-Comment relationship (One-to-Many)
expmvc sr Post Comment hasMany
# Scaffold User-Comment relationship (One-to-Many)
expmvc sr User Comment hasMany4. Generate Complete CRUD with Relationships:
# Generate User scaffold
expmvc generate scaffold User name:string email:string password:string
# Generate Post scaffold with User reference
expmvc generate scaffold Post title:string content:string user:ref:User
# Then add the reverse relationship
expmvc rel hasMany User Post --field postsField Types Supported
# Available field types:
name:string # String field
age:number # Number field
isActive:boolean # Boolean field
createdAt:date # Date field
tags:array # Array field
userId:objectid # ObjectId reference✨ Why Use This Generator?
Saves Hours: Skip repetitive setup and focus on business logic
Consistent Architecture: Enforces clean, maintainable structure
Production Ready: Includes validation, services, and middleware patterns
Scalable: Perfect for growing applications
Developer Friendly: Intuitive CLI with helpful commands
Perfect For:
Students learning Express.js
Backend developers starting new projects
Startups needing rapid prototyping
API bootstrapping and hackathons
Enterprise applications requiring structure
🔧 Advanced Usage
Custom Templates
You can customize the generated templates by modifying the generator files in your global installation.
Integration with Existing Projects
If you have an existing Express project with the same structure, you can still use the generator commands:
cd existing-express-project
expmvc generate scaffold Post title:string content:stringEnvironment Variables
Created .env file in your project root:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/yourdb❤️ Contributing
We welcome contributions! Here's how you can help:
1.Report Bugs: Open an issue with detailed description
2.Request Features: Suggest new features or improvements
3.Submit PRs: Fork the repo and submit pull requests
4.Improve Documentation: Help make the docs better
Thanks for using exp-mvc! Don't forget to give a ⭐ on GitHub if you like it!
Built with ❤️ for the Node.js community.
