Scaffold a production-ready MERN stack app in seconds.
Like create-next-app β but for MERN + Vite + TypeScript.
npx mern-builder my-appNo installation required. Just run and answer a few questions.
Or pass the project name later:
npx mern-builder # interactive β prompts for name
npx mern-builder my-app # name pre-filled, rest is interactiveThe CLI walks you through a fully interactive setup with section-by-section prompts. After answering all questions, you get a summary screen where you can go back and edit any section before the project is generated.
β Project Setup
β Frontend
β Backend
β DevOps & Tooling
β Review your choices β edit anything before confirming
β Scaffold!
| Option | Choices |
|---|---|
| Package manager | npm Β· pnpm (recommended) Β· yarn |
| Install deps now | yes / no |
| Init git repo | yes / no |
| Option | Choices |
|---|---|
| UI Library | Tailwind CSS Β· MUI v6 Β· shadcn/ui |
| Routing | None Β· React Router v6 Β· TanStack Router |
| State management | None Β· Zustand Β· Redux Toolkit Β· Jotai |
Path alias @/ |
yes / no |
| Option | Choices |
|---|---|
| Database | MongoDB (Mongoose) Β· PostgreSQL (Prisma) Β· MySQL (Prisma) Β· None |
| Authentication | None Β· JWT Β· JWT + Refresh Token |
| CORS | yes / no |
| Logger | None Β· Pino Β· Winston |
| Security middleware | Rate limiting Β· Helmet.js Β· Zod env validation |
| Option | Choices |
|---|---|
| Docker | None Β· Dockerfiles Β· docker-compose |
| Testing | None Β· Vitest Β· Vitest + Supertest |
| Code quality | ESLint + Prettier Β· Husky + lint-staged |
my-app/
βββ frontend/ # Vite + React 18 + TypeScript
β βββ src/
β β βββ components/ # your UI components
β β βββ hooks/ # useApi, useLocalStorage
β β βββ pages/ # route-level page components
β β βββ routes/ # React Router / TanStack route files
β β βββ services/
β β β βββ api.ts # axios client (with auth interceptors)
β β βββ store/ # Zustand / Redux / Jotai / Context
β β βββ types/ # shared TypeScript types
β βββ vite.config.ts
β βββ Dockerfile # (if Docker selected)
β
βββ backend/ # Express + TypeScript
β βββ src/
β β βββ config/
β β β βββ env.ts # Zod-validated environment
β β β βββ database.ts # MongoDB / Prisma connection
β β β βββ cors.ts # CORS options
β β βββ controllers/
β β βββ middleware/
β β β βββ errorHandler.ts # global error + Zod error handling
β β β βββ auth.ts # JWT authenticate + authorize
β β β βββ rateLimiter.ts
β β βββ models/ # Mongoose models / Prisma schema
β β βββ routes/
β β βββ utils/
β β βββ logger.ts # Pino / Winston
β β βββ jwt.ts # sign + verify helpers
β βββ prisma/ # (if PostgreSQL / MySQL)
β βββ Dockerfile # (if Docker selected)
β
βββ docker-compose.yml # (if compose selected)
βββ .vscode/ # editor settings + extension recommendations
βββ package.json # root workspace: dev, build, lint, test
- Vite + React 18 with hot module replacement out of the box
- TypeScript with strict mode and path aliases (
@/βsrc/) - Axios API client β pre-configured with base URL, timeout, and optional JWT interceptors + silent refresh on 401
useApihook β typed, reusable data-fetching hook withloading/error/datastateuseLocalStoragehook β cross-tab synced withStorageEvent- Full UI library setup: MUI theming, shadcn/ui CSS variables + dark mode, or plain Tailwind
- Express with
express-async-errorsβ no manualtry/catchin every route - Graceful shutdown handling
SIGTERM/SIGINT - Global error handler β normalises
AppError,ZodError, and unknown errors into a consistent JSON response - JWT auth with role-based
authorize()middleware; refresh-token flow useshttpOnlycookies - Zod env validation β server refuses to start if
.envis misconfigured - Structured logging β Pino with
pino-prettyin dev and JSON + log-level routing in production; Winston withDailyRotateFile
- Multi-stage Dockerfiles β build stage + minimal production image with health-check
- docker-compose β frontend (nginx), backend, and database service with health-checks
- Nginx config with SPA routing and
/apiproxy
cd my-app
# 1. Configure environment
cp backend/.env.example backend/.env
# β fill in DB connection string, JWT secrets, etc.
# 2. Start development servers (frontend + backend concurrently)
pnpm dev
# Frontend β http://localhost:5173
# Backend β http://localhost:5000
# API β http://localhost:5000/api/v1
# 3. Build for production
pnpm buildcd backend
pnpm db:generate # generate Prisma Client
pnpm db:migrate # run migrations
pnpm db:studio # open Prisma Studio GUIpnpm docker:build # build images
pnpm docker:up # start all services (detached)
pnpm docker:logs # tail logs
pnpm docker:down # stop servicesThe generated backend exposes:
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/health |
Health check | β |
POST |
/api/v1/auth/register |
Register new user | β |
POST |
/api/v1/auth/login |
Login | β |
GET |
/api/v1/auth/me |
Get current user | β JWT |
POST |
/api/v1/auth/refresh |
Refresh access token | πͺ Cookie |
POST |
/api/v1/auth/logout |
Logout | β JWT |
GET |
/api/v1/users |
List users | β |
GET |
/api/v1/users/:id |
Get user by ID | β |
Some endpoints are only generated based on your auth strategy selection.
The generated backend/.env.example includes everything you need:
PORT=5000
NODE_ENV=development
LOG_LEVEL=debug
# Database (one of the following)
MONGODB_URI=mongodb://localhost:27017/my-app
DATABASE_URL=postgresql://postgres:secret@localhost:5432/my-app?schema=public
# JWT (if auth selected)
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
JWT_EXPIRES_IN=15m
# JWT Refresh (if jwt-refresh selected)
JWT_REFRESH_SECRET=your-refresh-secret-min-32-chars
JWT_REFRESH_EXPIRES_IN=7d
# CORS (if selected)
ALLOWED_ORIGINS=http://localhost:5173
β οΈ Always change the JWT secrets before deploying to production. Never commit your.envfile.
git clone https://github.com/kirtanp04/create-mern-cli
cd mern-builder
npm install
# Run without building (ts-node)
npm run dev
# Build to dist/
npm run build
# Test locally
npm link
mern-builder test-projectContributions, issues, and feature requests are welcome!
- Fork the repo
- Create your branch:
git checkout -b feat/my-feature - Commit your changes:
git commit -m 'feat: add my feature' - Push to the branch:
git push origin feat/my-feature - Open a Pull Request
Please follow Conventional Commits for commit messages.
| Requirement | Version |
|---|---|
| Node.js | >= 18.0.0 |
| npm / pnpm / yarn | any recent version |
MIT Β© 2024 β made with β and TypeScript.