UNPKG

create-mern-server

Version:

โšก Instantly scaffold a production-ready MERN server using JavaScript or TypeScript.

167 lines (113 loc) โ€ข 3.37 kB
# create-mern-server > ๐Ÿš€ Instantly scaffold a production-ready MERN backend using JavaScript or TypeScript โ€” complete with Express, MongoDB, Prettier, and more. --- ## โœจ Features - โœ… Clean folder structure (MVC pattern) - โš™๏ธ Express + MongoDB with Mongoose setup - ๐ŸŽฏ Choose between **JavaScript** or **TypeScript** - ๐Ÿ”ง Optional Prettier configuration - ๐Ÿงช Environment configuration via `.env` - ๐Ÿ” Nodemon for development (JS) / `tsc` build (TS) - ๐Ÿ“ Ready-to-use folders: `controllers`, `routes`, `models`, `middlewares`, `utils`, etc. - ๐Ÿ“ฆ Auto-installs dependencies & sets up Git - ๐Ÿ“œ Generates `README.md`, `.gitignore`, `.prettierrc`, and `tsconfig.json` --- ## ๐Ÿ“ฆ Installation You can use `npx` (no install needed): ```bash npx create-mern-server ```` Or install globally: ```bash npm install -g create-mern-server ``` --- ## ๐Ÿš€ Getting Started Run the CLI tool: ```bash npx create-mern-server ``` ### You'll be prompted to: 1. ๐Ÿ“ Enter your **project name** 2. ๐ŸŒ Choose **JavaScript** or **TypeScript** 3. ๐ŸŽจ Decide whether to use **Prettier** --- ## ๐Ÿ—‚ Folder Structure The tool generates this clean folder structure: ``` server/ โ”œโ”€โ”€ public/ โ”‚ โ””โ”€โ”€ temp/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ controllers/ โ”‚ โ”œโ”€โ”€ db/ โ”‚ โ”œโ”€โ”€ middlewares/ โ”‚ โ”œโ”€โ”€ models/ โ”‚ โ”œโ”€โ”€ routes/ โ”‚ โ”œโ”€โ”€ utils/ โ”‚ โ””โ”€โ”€ index.ts|js โ”œโ”€โ”€ .env โ”œโ”€โ”€ .gitignore โ”œโ”€โ”€ .prettierrc (optional) โ”œโ”€โ”€ .prettierignore (optional) โ”œโ”€โ”€ tsconfig.json (for TypeScript) โ”œโ”€โ”€ README.md โ””โ”€โ”€ package.json ``` --- ## โš™๏ธ Scripts For JavaScript projects: ```bash npm run dev # Uses nodemon + dotenv ``` For TypeScript projects: ```bash npm run dev # Compiles with tsc, runs built code with dotenv ``` --- ## ๐Ÿ” Environment Variables A `.env` file is generated: ```env PORT = 1604 MONGODB_URI = your-mongodb-url CORS_ORIGIN = http://localhost:5173 ``` --- ## ๐Ÿ“˜ Example Output A minimal working Express server (`index.js` or `index.ts`) and MongoDB connector (`connectDB.ts|js`) are created. Example: ```ts import express from "express"; import dotenv from "dotenv"; import cors from "cors"; import cookieParser from "cookie-parser"; import connectDB from "./db/connectDB"; dotenv.config(); const app = express(); app.use(cors({ origin: process.env.CORS_ORIGIN, credentials: true })); app.use(express.json()); app.use(cookieParser()); connectDB().then(() => { app.listen(process.env.PORT, () => console.log(`Server running at http://localhost:${process.env.PORT}`) ); }); ``` --- ## ๐Ÿ”ง Customization Once generated, you can: * Add new routes under `src/routes/` * Connect controllers, models, and middleware * Configure Prettier or ESLint * Extend with JWT, auth, or any additional service --- ## ๐Ÿค Contributing Contributions, issues, and feature requests are welcome! Feel free to open a [Pull Request](https://github.com/Naman-Tulsyan/create-mern-server/pulls) or [Issue](https://github.com/Naman-Tulsyan/create-mern-server/issues). --- ## ๐Ÿ‘จโ€๐Ÿ’ป Author Developed and maintained by [**Naman Tulsyan**](https://github.com/Naman-Tulsyan) --- ## โญ๏ธ Show Your Support If you found this helpful, please consider giving a โญ๏ธ on [GitHub](https://github.com/Naman-Tulsyan/create-mern-server.git)!