UNPKG

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
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) ``` ---