A high-performance mock API and file management system for rapid frontend development and prototyping.
Backend for Devs is a lightweight, configurable backend server built on top of JSON Server. It is designed to provide frontend engineers with a realistic development API that supports CRUD operations, static file serving, file uploads, and optional clustering for high‑load testing.
This project emphasizes simplicity, speed, and ease of use—everything you need to spin up a local API in seconds without writing a single line of backend code.
- Full REST API automatically generated from
store/data/db.json. - File Upload Support via
multipart/form-datausingmulterwith checksum‑based renaming. - Static Asset Serving from
/publicendpoint. - Cluster Mode for multi‑core load simulation using Node's
clustermodule. - Middleware Inspection with request/response logging and body adaptation.
- JWT‑based Authentication with login endpoint and route protection.
- Simple Configuration—everything is handled through code conventions and a single JSON file.
- Node.js (LTS recommended, v18+)
- npm or yarn
cd backdev
npm installStart the server with automatic restarts using nodemon:
npm run devThe API will be available on http://localhost:3000 (or the port specified by PORT).
Default response:
The Backend for Devs is listened at port 3000
To spawn one worker per CPU core and simulate a production‑like environment:
npm startThis runs src/cluster.js, which forks the main server into multiple instances.
backdev/
├── src/
│ ├── adapter.js # request/response middleware
│ ├── auth.js # JWT auth and login handler
│ ├── cluster.js # cluster launcher
│ ├── fileUtils.js # file I/O helpers
│ ├── main.js # entrypoint for single‑process mode
│ ├── Server.js # JSON Server configuration
│ ├── storage.js # multer storage and static routes
│ └── Multer/DiskStorage.js
├── store/
│ ├── data/db.json # mock database
│ └── public/ # uploaded files served statically
├── package.json
└── README.md
- Database: edit
store/data/db.json; every top‑level key becomes a REST resource. - Static route: files stored under
store/public/<resource>are served at/public. - Authentication: modify
SECRET_KEYand payload structure insrc/auth.js. - Upload behaviour: customize hashing, renaming, and cleanup in
src/storage.js. - Middleware: adapt request/response logging, body coercion, or resource‑specific adapters in
src/adapter.js.
- Client POSTs/PUTs to a resource endpoint with
Content-Type: multipart/form-data. multerintercepts and saves files tostore/public/<resource>.- After upload, files are renamed using a SHA256 hash.
- Middleware logs upload details and ensures the incoming JSON body fields are normalized.
Files can then be accessed via GET /public/<resource>/<filename>.
- Login:
POST /loginwith JSON body{ "email": "...", "password": "..." }. - JWT: response includes a
tokenfield (Bearer <token>). - Protected Routes: all following routes are guarded by
AuthMiddlewareonce login is successful.
The middleware checks for the Authorization header and verifies the JWT using a hard‑coded secret.
"dependencies": {
"express": "^4.18.2",
"express-interceptor": "^1.2.0",
"json-server": "^0.17.1",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"nodemon": "^2.0.20"
}Create or update a user:
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d '{"name":"Alice","email":"alice@mail.com"}'Upload a file to products:
curl -F "file=@/path/to/image.jpg" http://localhost:3000/productsLogin and use the token:
curl -X POST http://localhost:3000/login -d '{"email":"admin@mail.com","password":"admin123"}'
# copy token from response
curl http://localhost:3000/users -H "Authorization: Bearer <token>"No automated tests are provided by default, but the endpoint behavior can be verified using the .insomnia collection included in the project. Import it into Insomnia or any other API client.
The .insomnia folder contains a workspace with predefined requests, environments, and unit tests to exercise the API.
- To reset the database, simply edit or replace
store/data/db.json. - Uploaded files are permanent; manually clean
store/publicif necessary. - Cluster mode forks workers automatically on crash (except for graceful exits).
MIT License. Developed by Luis Caldas.
Feel free to fork or adapt for your own projects—for devs, by devs!