# JSON Server — Full Fake REST API with Zero Coding > A Node.js tool that turns a JSON file into a fully functional REST API in seconds. Useful for frontend prototyping, mocking backends during development, and creating demo APIs without writing any server code. ## Install Save in your project root: # JSON Server — Full Fake REST API with Zero Coding ## Quick Use ```bash npm install -g json-server echo '{"posts":[{"id":1,"title":"Hello"}]}' > db.json json-server --watch db.json ``` ## Introduction JSON Server provides a full fake REST API from a single JSON file. It was created to let frontend developers prototype and develop against a realistic API without waiting for backend teams. Point it at a `db.json` file and you get GET, POST, PUT, PATCH, and DELETE routes with pagination, filtering, sorting, and full-text search. ## What JSON Server Does - Creates RESTful CRUD endpoints from any JSON file automatically - Supports filtering, pagination, sorting, and full-text search via query parameters - Watches the JSON file for changes and reflects them in real time - Serves static files from a `public` directory alongside the API - Supports custom routes, middleware, and programmatic usage as a Node.js module ## Architecture Overview JSON Server is built on Express.js. It reads a JSON file as an in-memory lowdb database, generates RESTful routes for each top-level key, and writes changes back to the file. Custom middleware can be added to intercept requests, and a `routes.json` file enables URL rewriting to simulate complex API structures. ## Self-Hosting & Configuration - Install globally with npm or use npx for one-off usage without installation - The `--port` flag changes the default port from 3000 - Add a `routes.json` file for custom URL mappings like `/api/v1/posts` to `/posts` - Use `--middlewares` to inject custom Express middleware for auth simulation or logging - Mount JSON Server as middleware inside an existing Express app for hybrid setups ## Key Features - Instant REST API from a flat JSON file with zero boilerplate - Full CRUD operations with automatic ID generation for new records - Query parameter support for `_page`, `_limit`, `_sort`, `_order`, and `q` (search) - Relationships via `_expand` and `_embed` for nested resource responses - Snapshot feature saves the current database state on demand ## Comparison with Similar Tools - **MSW (Mock Service Worker)** — intercepts requests at the network level in the browser; JSON Server runs as a real HTTP server - **Mirage.js** — in-memory mock server that runs in the browser; JSON Server provides a standalone process accessible from any client - **WireMock** — Java-based HTTP mock with request matching; heavier setup than JSON Server's single-file approach - **Mockoon** — desktop GUI for designing mock APIs; JSON Server is CLI-first and scriptable ## FAQ **Q: Does JSON Server persist data?** A: Yes, changes are written back to the JSON file on disk. Restarting the server reloads from the file. **Q: Can I use it in production?** A: JSON Server is designed for development and prototyping. It uses a flat file as storage and lacks authentication, rate limiting, and other production requirements. **Q: How do I add authentication?** A: Add custom Express middleware via the `--middlewares` flag or mount JSON Server inside a larger Express app that handles auth. **Q: Does it support nested resources?** A: Use `_embed` to include child resources and `_expand` to include parent resources in responses. ## Sources - https://github.com/typicode/json-server - https://github.com/typicode/json-server#getting-started --- Source: https://tokrepo.com/en/workflows/asset-b92132b4 Author: AI Open Source