create-express-mongo-server
Version:
CLI to scaffold an Express.js + MongoDB backend with optional CORS and Nodemon support.
157 lines (104 loc) β’ 2.95 kB
Markdown
Hereβs a detailed `README.md` file for your **create-express-mongo-server** CLI project:
````markdown
# π create-express-mongo-server
A simple CLI tool to quickly scaffold a Node.js + Express.js backend with MongoDB integration, optional CORS support, and development with Nodemon.
## π¦ Features
- βοΈ Auto-generated folder structure (`routes`, `controllers`, `db`)
- π± MongoDB integration using Mongoose
- π Environment variable support via `.env`
- π Optional CORS setup
- π Optional Nodemon for live reload
- β
Pre-configured starter code (`server.js`, example route & controller)
- π Installs all necessary dependencies
## π Getting Started
### Step 1: Install the CLI globally
```bash
npm install -g create-express-mongo-server
````
### Step 2: Run the CLI
```bash
npx create-express-mongo-server
```
### You will be prompted for:
* Project name
* MongoDB URI
* Whether to enable CORS
* Whether to use Nodemon
The project will be created in a new directory with the name you specify.
## π Project Structure
```
your-project-name/
βββ controllers/
β βββ userController.js
βββ db/
β βββ db.js
βββ routes/
β βββ users.js
βββ .env
βββ package.json
βββ server.js
```
## βοΈ .env Configuration
The `.env` file contains the following variables:
```env
MONGO_URI=your-mongodb-uri
PORT=5000
```
## π§© Scripts
Available scripts in `package.json`:
| Script | Description |
| ------------- | ----------------------------------------------- |
| `npm start` | Starts the server using Node |
| `npm run dev` | Starts the server using Nodemon *(if selected)* |
## π§ͺ Sample API Route
Test route is available at:
```
GET /api/users
```
Sample response:
```json
[
{ "id": 1, "name": "John" },
{ "id": 2, "name": "Smith" }
]
```
## π¦ Dependencies
* `express` β Web framework
* `mongoose` β MongoDB ODM
* `dotenv` β Environment variable management
* `cors` *(optional)* β Cross-Origin Resource Sharing
* `nodemon` *(optional)* β Auto-restarting dev server
## π Example Usage
```bash
# Step 1: Navigate into the project folder
cd your-project-name
# Step 2: Install dependencies (if not done already)
npm install
# Step 3: Start the server
npm run dev # if nodemon enabled
# or
npm start # if nodemon not enabled
```
## π Graceful Shutdown
The server and MongoDB connection will close properly on:
* `Ctrl + C` (SIGINT)
* MongoDB disconnection events
* Unhandled promise rejections
## π License
MIT License Β© 2025
## π¨βπ» Author
Built with β€οΈ by [Abdul](https://github.com/Abdulgsk)
```