@iesparag/create-backend
v1.0.0
Published
One-command scaffold for a Node.js + Express + MongoDB + Socket.io backend (ESM, MVC).
Maintainers
Readme
create-backend
A small CLI I use to spin up new Node.js backends without copy-pasting the same boilerplate every time. Run one command, get a working Express + MongoDB + Socket.io API with the folder structure, middlewares and auth already in place.
Since I only use it for backends, the generated folder gets a -backend suffix by
default (my-api becomes my-api-backend). Use --no-suffix if you don't want that.
Stack: Node.js (ESM), Express, Mongoose, Socket.io, JWT, Zod.
Usage
Three ways to run it depending on whether it's published / installed:
# via npx (once published, nothing to install)
npx @iesparag/create-backend my-api
# installed globally (or `npm link` from source)
npm i -g @iesparag/create-backend
create-backend my-api
# straight from source, no install
node bin/create.js my-apiAll of them create ./my-api-backend. Then:
cd my-api-backend
cp .env.example .env # set MONGODB_URI and JWT_SECRET
npm install
npm run dev # http://localhost:5000Flags: --no-suffix, -h/--help, -v/--version. If you don't pass a name it
asks for one.
Publishing
Published under a scoped name (@iesparag/create-backend) since the plain
create-backend was already taken on the registry. Scoped packages are private by
default, so the first publish needs --access public:
npm login
npm pack --dry-run # sanity check what gets shipped
npm publish --access publicTo test the "no global install" path without publishing: npm pack, then in some
other project npm i ./create-backend-1.0.0.tgz.
What the generated project looks like
src/
├── config/ env validation (zod) + mongoose connection
├── controllers/ request/response only, no business logic
├── services/ business logic
├── models/ mongoose schemas (User with auth built in)
├── routes/ /api/v1 routes + an aggregator
├── middlewares/ error, 404, auth + authorize, validate, rate limit
├── validations/ zod schemas per resource
├── sockets/ socket.io server + example handlers
├── utils/ ApiError, ApiResponse, asyncHandler, logger
├── app.js express app + middleware pipeline
└── server.js http + socket + db connect + graceful shutdownIt ships with working User register/login/me endpoints and a small Socket.io demo
(ping with ack, join room, broadcast). To add a new feature I just follow the same
four files: model, service, controller, route, then mount it in routes/index.js.
Notes
bin/create.jsis the generator. No dependencies, just Node built-ins.template/is what gets copied. The gitignore lives there asgitignore(without the dot) because npm strips dotfiles on publish; the generator writes it back out as.gitignorewhen scaffolding.- Other starter kits can live next to this one under
starter-kits/.
