@ldpld/create-node-mvc
v0.1.1
Published
Express.js MVC Scaffold Generator - Create production-ready Node.js projects with dual-route architecture
Downloads
73
Maintainers
Readme
create-node-mvc
Express.js MVC Scaffold Generator - Create production-ready Node.js projects with dual-route architecture.
Installation
Install globally via npm:
npm install -g create-node-mvcOr use with npx (no installation required):
npx create-node-mvc my-projectUsage
create-node-mvc <project-name>The CLI will guide you through an interactive setup with the following options:
- API-only architecture: Generate API routes only (no view rendering)
- Include authentication: Add JWT-based authentication system
- Additional features: Select from:
- File uploads (express-fileupload)
- Email service (nodemailer)
- Testing setup (Jest + Supertest)
- Tailwind CSS (with build pipeline)
Command Options
create-node-mvc <project-name> [options]Options:
--skip-install: Skip automaticnpm installafter project generation
Examples:
# Create project with interactive prompts and auto-install
create-node-mvc my-api
# Create project and skip dependency installation
create-node-mvc my-api --skip-installRunning Tests
Run all tests:
npm testRun tests with coverage:
npm test -- --coverageRun specific test file:
npm test -- tests/project-structure.test.jsUpdate snapshots (when intentional changes occur):
npm test -- -uTest execution time:
- Unit tests: ~5-10 seconds
- Integration tests: ~20-30 seconds (without server startup)
- Server startup tests: ~2-3 minutes (includes npm install)
- Full suite: ~3-4 minutes
Test coverage goals:
- lib/ modules: >80% coverage
- Integration coverage: All configuration combinations
- Edge cases: Error handling scenarios
Development
Project Structure
cli/
├── bin/
│ └── create-node-mvc.js # CLI entry point
├── lib/
│ ├── prompts.js # Interactive questions
│ ├── fileOperations.js # File copying/operations
│ ├── variableReplacer.js # Template variable substitution
│ ├── featureIntegration.js # Optional feature integration
│ └── dependencyInstaller.js # npm install automation
├── templates/
│ ├── base/ # Core project template
│ └── optional/ # Feature-specific templates
└── tests/ # Test suiteAdding New Features
- Add template files to
templates/optional/<feature-name>/ - Update
lib/featureIntegration.jswith merge logic - Add feature to prompts in
lib/prompts.js - Write tests in
tests/feature-validation.test.js
Generated Project Structure
Full MVC Project (Default)
your-project/
├── config/
│ ├── config.env # Environment configuration
│ └── db.js # MongoDB connection setup
├── controllers/
│ ├── api/
│ │ └── user.controller.js # API endpoint handlers
│ ├── view/
│ │ └── user.controller.js # View rendering handlers
│ └── error.js # 404 error handler
├── middleware/
│ ├── advancedResults.js # Query filtering, pagination
│ ├── async.js # Async error wrapper
│ ├── auth.js # JWT authentication
│ └── error.js # Global error handler
├── models/
│ └── User.js # Mongoose User model
├── routes/
│ ├── api/
│ │ └── user.routes.js # API routes (/api/v1/users)
│ └── view/
│ └── user.routes.js # View routes (/users)
├── utils/
│ ├── errorResponse.js # Custom error class
│ ├── geocoder.js # Geocoding utilities
│ ├── path.js # Path helpers
│ └── saveToDisk.js # File upload utilities
├── views/
│ ├── users/
│ │ ├── list.ejs # User list view
│ │ ├── show.ejs # User detail view
│ │ ├── new.ejs # Create user form
│ │ └── edit.ejs # Edit user form
│ ├── partials/
│ │ ├── header.ejs # Reusable header
│ │ └── footer.ejs # Reusable footer
│ └── 404.ejs # Error page
├── public/
│ ├── css/
│ │ └── main.css # Stylesheet
│ ├── src/imgs/
│ │ └── ava-img-blue.svg # Example image
│ └── index.html # Static homepage
├── .env.example # Environment template
├── .gitignore # Git ignore rules
├── app.js # Express app entry point
├── package.json # Dependencies
└── README.md # Project documentationDual-Route Architecture
Generated projects support both API and view routes:
API Routes (
/api/v1/*): JSON responses for REST clients- Controllers:
controllers/api/ - Routes:
routes/api/ - Example:
GET /api/v1/users→ Returns JSON
- Controllers:
View Routes (
/*): Server-rendered EJS templates- Controllers:
controllers/view/ - Routes:
routes/view/ - Views:
views/ - Example:
GET /users→ Renders HTML page
- Controllers:
API-Only Mode
When "API-only architecture" is selected, the structure excludes:
your-project/
├── config/
├── controllers/
│ ├── api/ # ✓ API controllers only
│ └── error.js
├── middleware/
├── models/
├── routes/
│ └── api/ # ✓ API routes only
├── utils/
├── .env.example
├── .gitignore
├── app.js
├── package.json
└── README.md
# Excluded in API-only mode:
# ✗ views/
# ✗ public/
# ✗ controllers/view/
# ✗ routes/view/Optional Features
When selected, additional files are added:
Authentication (--auth):
controllers/api/protected.controller.jsroutes/api/protected.routes.js- Enhanced
middleware/auth.js - JWT environment variables in
.env
File Upload (--fileupload):
controllers/api/upload.controller.jsroutes/api/upload.routes.jsutils/fileUpload.js- Upload directory configuration
Email Service (--email):
controllers/api/email.controller.jsutils/sendEmail.js- SMTP environment variables
Testing (--testing):
tests/api/user.test.jstests/setup.jsjest.config.js- Test scripts in
package.json
Tailwind CSS (--tailwind):
tailwind.config.jspostcss.config.jspublic/css/input.css- Enhanced view templates with Tailwind classes
- Build scripts in
package.json
License
MIT
