create-mern-server
Version:
โก Instantly scaffold a production-ready MERN server using JavaScript or TypeScript.
167 lines (113 loc) โข 3.37 kB
Markdown
# 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)!