@sahil5261/create-mern-crud
v2.0.4
Published
CLI to scaffold a MERN CRUD app: React+Vite+Router+Redux Toolkit+Tailwind, Node+Express+Mongoose with services/controllers/routes/models/middleware, async handler, centralized error handling, env config
Readme
create-mern-crud
A CLI that scaffolds a complete, working MERN CRUD app in one command — React + Vite + React Router + Redux Toolkit + Tailwind CSS on the frontend, Node + Express + MongoDB/Mongoose on the backend, with a proper services → controllers → routes layered structure, centralized error handling, and toast notifications already wired up. Optional add-ons: Redis and a full Stripe Checkout + webhook payment flow.
Usage
npx @your-npm-username/create-mern-crud my-appor run it with no project name and answer the prompt:
npx @your-npm-username/create-mern-crudYou'll be asked:
? Project name: my-app
? Name of your CRUD resource? (e.g. Item, Product, Task) Item
? Set up Redis (optional cache / session store, not wired into any route)? (y/N)
? Set up payment gateway (Stripe Checkout + webhook)? (y/N)
? Install dependencies now? (Y/n)Then:
cd my-app/server && cp .env.example .env # fill in MONGO_URI
npm install && npm run dev
cd my-app/client
npm install && npm run devWhat you get
- CRUD resource named whatever you typed (arbitrary input is sanitized into a safe identifier —
simple-crudbecomesSimpleCrud), with full Create/Read/Update/Delete wired end-to-end: Mongoose model → service layer → controller (throws a standardApiError) → Express router → Redux Toolkit slice → React components. - Centralized error handling — every thrown
ApiError(statusCode, message)is caught by one Express error-handling middleware, so the HTTP status code you get back always matches what was actually thrown. - Toasts — success and error notifications, top-right, via
react-hot-toast. - Redis (optional) — an
ioredisclient inserver/config/redis.js, ready to import for caching or rate-limiting. Not wired into any route by default, so declining it removes the file and dependency cleanly. - Payments (optional) — Stripe Checkout Session creation + a signature-verified webhook that persists payment status to MongoDB via a
Paymentmodel. See the generated project's ownREADME.mdfor full local-testing instructions (Stripe test keys, the Stripe CLI for local webhook delivery, test card numbers) — webhooks specifically need that setup sincelocalhostisn't reachable from Stripe's servers on its own.
Full docs
Once generated, my-app/README.md documents the exact stack, folder structure, API routes, and (if enabled) the complete payment testing walkthrough for that specific project.
