# json-server — Full Fake REST API with Zero Coding > A Node.js tool that creates a complete REST API from a single JSON file in under 30 seconds, perfect for front-end prototyping and testing. ## Install Save in your project root: # json-server — Full Fake REST API with Zero Coding ## Quick Use ```bash npm install -g json-server # Create a db.json file echo '{"posts":[{"id":"1","title":"hello"}]}' > db.json json-server db.json # API available at http://localhost:3000/posts ``` ## Introduction json-server gives front-end developers a fully functional REST API backed by a plain JSON file. It supports GET, POST, PUT, PATCH, DELETE, filtering, pagination, sorting, and full-text search out of the box, letting teams prototype and test without waiting for a real backend. ## What json-server Does - Generates RESTful routes from any JSON file automatically - Supports filtering, pagination, sorting, and full-text search via query parameters - Watches the JSON file for changes and reloads data live - Serves static files alongside the API - Supports custom routes, middlewares, and module-based usage in Node.js ## Architecture Overview json-server is built on Express.js and uses lowdb (a small local JSON database) to persist data. When you start the server, it reads your JSON file, creates RESTful endpoints for each top-level key, and writes mutations back to disk. The v1 branch simplified the codebase and added native TypeScript support. ## Self-Hosting & Configuration - Install globally via npm or use npx for one-off runs - Structure your `db.json` with top-level keys as resource collections - Use `--port` to change the default port from 3000 - Add a `routes.json` file to define custom URL rewrites - For programmatic use, import json-server as a module and attach custom middleware ## Key Features - Zero configuration required for basic REST operations - Supports nested resources and relationship expansion via `_embed` and `_expand` - Custom routes allow URL aliasing for realistic API simulation - Middleware support for authentication stubs and logging - Snapshot feature saves the current database state to a file ## Comparison with Similar Tools - **Mirage JS** — runs in the browser, intercepts fetch/XHR; json-server runs as a real HTTP server - **MSW (Mock Service Worker)** — intercepts requests at the network level; json-server provides a standalone server process - **Prism (Stoplight)** — generates mock servers from OpenAPI specs; json-server works from plain JSON - **WireMock** — Java-based HTTP mock server for contract testing; heavier setup - **Mockoon** — desktop app with GUI for mock APIs; json-server is CLI-first and scriptable ## FAQ **Q: Can json-server handle large datasets?** A: It works well for development and prototyping. For datasets beyond a few thousand records, consider a real database since lowdb reads the entire file into memory. **Q: Does json-server support authentication?** A: Not natively, but you can add Express middleware to handle JWT or basic auth. **Q: Can I use json-server with TypeScript projects?** A: Yes. Version 1.x ships with TypeScript types and can be imported as an ES module. **Q: Is data persistent across restarts?** A: Yes. Changes are written back to the JSON file, so data survives server restarts. ## Sources - https://github.com/typicode/json-server - https://github.com/typicode/json-server#getting-started --- Source: https://tokrepo.com/en/workflows/4e7a46ad-4384-11f1-9bc6-00163e2b0d79 Author: AI Open Source