· articles · 4 min read

By Ankit Jain

How to Install JSON-Server

JSON-Server lets you spin up a fake REST API in minutes. You avoid backend wait time, keep frontend work moving, and test real API flows without setup overhead.

JSON-Server lets you spin up a fake REST API in minutes. You avoid backend wait time, keep frontend work moving, and test real API flows without setup overhead.

Why Frontend Developers Reach for JSON-Server

If you build frontend or mobile apps, you have likely hit this wall. The UI is ready to move forward, but the backend APIs are still being built, reviewed, or deployed. You end up waiting, hardcoding mock data, or changing code again once real APIs arrive.

JSON-Server solves this gap cleanly. It gives you a full REST API backed by a simple JSON file. You can create endpoints, return realistic responses, and test flows without depending on backend availability. This keeps frontend work unblocked and lets you iterate faster.

With JSON-Server, you define your data once and instantly get endpoints for listing, creating, updating, and deleting records. No framework setup. No database. Just a JSON file and a running server.

Prerequisites

Before installing JSON-Server, you need Node.js and npm on your system. JSON-Server runs on top of Node, and npm is used to install it.

Install Node.js and npm

  1. Open the official Node.js download page
    https://nodejs.org/en/download/package-manager

  2. Download the installer for your operating system.

  3. Run the installer and make sure npm is selected during installation.

  4. Verify the setup by running the following commands in your terminal:

node -v
npm -v

If both commands print version numbers, you are ready to proceed.

Installing JSON-Server

With Node.js and npm ready, you can proceed to install JSON-Server.

Installation Steps

  1. Open Terminal or Command Prompt: This will be used for inputting installation commands.
  2. Install JSON-Server Globally: Execute the command npm install -g json-server. A global installation allows for easy access from any project directory.

Configuration and Usage

Setting up and starting your mock API with JSON-Server involves creating a JSON file and running the server.

Setting Up Your Mock API

JSON-Server works by reading data from a JSON file and exposing it as REST endpoints.

Create a db.json File

Create a new file named db.json. This file acts as your mock database.

Here is a sample structure that covers common API use cases:

{
  "posts": [
    { "id": 1, "title": "Exploring JSON-Server", "author": "Jane Kale" },
    { "id": 2, "title": "Advanced Mock APIs", "author": "Dab Smith" },
    { "id": 3, "title": "Debugging with Mocks", "author": "Alice Johnson" },
    { "id": 4, "title": "API Design Patterns", "author": "Bob Brown" },
    { "id": 5, "title": "The Future of APIs", "author": "Charlie Day" }
  ],
  "comments": [
    { "id": 1, "body": "Great article!", "postId": 1 },
    { "id": 2, "body": "Very informative.", "postId": 2 },
    { "id": 3, "body": "I ran into a small issue...", "postId": 1 },
    { "id": 4, "body": "Could you cover GraphQL?", "postId": 3 },
    { "id": 5, "body": "Excellent read.", "postId": 5 }
  ],
  "users": [
    { "id": 1, "name": "Alice", "occupation": "Developer" },
    { "id": 2, "name": "Bob", "occupation": "Designer" },
    { "id": 3, "name": "Charlie", "occupation": "Product Owner" },
    { "id": 4, "name": "David", "occupation": "Tech Lead" },
    { "id": 5, "name": "Eve", "occupation": "QA Engineer" }
  ]
}

Each top-level key becomes a REST resource. JSON-Server automatically generates routes based on these keys.

Starting the JSON-Server

  1. Navigate to Your JSON File Directory: Where your db.json is saved.
  2. Launch JSON-Server: Run the command json-server —watch db.json.
  3. Access Your Server: The server typically starts at http://localhost:3000/.
  4. Access your mock endpoints like http://localhost:3000/posts or http://localhost:3000/users from here.

When JSON-Server Is Not Enough

JSON-Server works well for quick local mocks, but it has limits. It runs locally, only returns JSON, and does not handle advanced scenarios like request inspection, binary responses, or OpenAPI imports.

This is where Beeceptor fits in.

Beeceptor gives you a hosted mock server without installing anything. You upload JSON or API definitions, and your mock endpoints are live instantly. You can inspect incoming HTTP requests, simulate failures, add delays, and return dynamic responses.

A few cases where Beeceptor is more practical than JSON-Server:

  • You do not want to install or run anything locally.
  • You need templated responses to generate fake or random data.
  • You want to mock binary responses like PDFs or images.
  • You already have an OpenAPI spec and want mock endpoints created automatically.

If you are working with teams, CI pipelines, or shared environments, a hosted mock server removes a lot of friction compared to local-only tools.

[Top]

Back to Blog