1.0.12 • Published 10 months ago

express-mod-cli v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Express Modular Generator

A command-line tool to generate Express.js applications with a modular architecture pattern.

Installation

npm install -g express-mod-cli

Usage

Create a new project

express-mod-cli create my-project

Go to Project Directory

cd projectName

Adding New Modules šŸ“¦

express-mod-cli add users

Example:

npx express-mod-cli add users

Run the Projects

npm run dev

Database Configuration šŸ”§

Local MongoDB Setup

  1. Update MongoDB URI env
  • Open the .env file located in the root of the project directory.
  • Replace the placeholder MongoDB URI with your actual MongoDB URI.
  • Example: MONGODB_URI=mongodb://localhost:27017/yourDB_name

MongoDB Atlas Setup ā˜ļø

If you prefer using MongoDB Atlas (cloud database):

  1. Get Your Connection String
    • Log in to MongoDB Atlas
    • Navigate to your cluster
    • Click "Connect"
    • Choose "Connect your application"
    • Copy the connection string
  2. Configure Atlas URI

    env For MongoDB Atlas MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/yourDB_name DB_NAME=yourDB_name PORT=5000

    Remember to replace <username>, <password>, and the rest of the URI with your actual MongoDB Atlas credentials

Environment Variables Explained šŸ“

VariableDescriptionExample
MONGODB_URIYour MongoDB connection stringmongodb://localhost:27017/yourDB_name
DB_NAMEName of your databaseyourDB_name
PORTIPort number for the server5000

Modules

Each module follows the Model-Controller-Route pattern and includes:

  • Model: Defines the database operations.
  • Controller: Manages the business logic for each route.
  • Routes: Maps HTTP methods to controller functions.

Default Endpoints (CRUD)

For each module, the following CRUD endpoints are available:

  • GET /module: Retrieve all items.
  • GET /module/:id: Retrieve a single item by ID.
  • POST /module: Create a new item.
  • PATCH /module/:id: Update an existing item by ID.
  • DELETE /module/:id: Delete an item by ID

Features

  • Modular architecture with Model-Route-Controller pattern
  • MongoDB integration
  • Error handling middleware
  • CORS and security headers
  • Environment configuration
  • Ready-to-use CRUD operations

Upcoming Features

  • Authentication: Adding user authentication with JWT for securing endpoints.
  • Route Authentication: Implementing route-level authentication middleware to restrict access to specific routes.

Project Structure

project/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ config/
│   │   └── db.js
│   ā”œā”€ā”€ middleware/
│   │   └── errorHandler.js
│   ā”œā”€ā”€ modules/
│   │   └── [module-name]/
│   │       ā”œā”€ā”€ module.model.js
│   │       ā”œā”€ā”€ module.controller.js
│   │       └── module.routes.js
│   ā”œā”€ā”€ utils/
│   └── index.js
ā”œā”€ā”€ .env
ā”œā”€ā”€ .gitignore
└── package.json

License

MIT

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.2

10 months ago

1.0.0

10 months ago