No Database? No Problem! Build Local Mock APIs with JSON Server
A Mock service simulates backend API data, enabling frontend developers to rapidly debug pages or test various data scenarios. This article demonstrates how to build a local Mock service in three simple steps using JSON Server, requiring only a JSON file and no database setup! Table of Contents 1. Prerequisites Install Node.js Install JSON Server 2. Building the Mock Service Step 1: Create a Mock Data File (db.json) Step 2: Start the JSON Server Step 3: Verify API Endpoints 3. Debugging and Extensions Auto-Update Data Debugging with Apidog 4. FAQ Port Conflicts Data Not Updating 5. Conclusion I. Prerequisites 1. Install Node.js Ensure Node.js is installed (download from https://nodejs.org). Verify by running in terminal: node -v && npm -v If version numbers are displayed, installation is complete. 2. Install JSON Server Open the terminal in your IDE (e.g., VS Code) and execute: npm install -g json-server If permission errors occur, try: sudo npm install -g json-server II. Building the Mock Service in 3 Steps Step 1: Create a Mock Data File Create a folder (e.g., mock-demo) and add a db.json file with the following content: { "users": [ { "id": 1, "name": "John Doe", "age": 25 }, { "id": 2, "name": "Jane Smith", "age": 30 } ], "posts": [ { "id": 1, "title": "First Post", "author": "John Doe" } ] }

A Mock service simulates backend API data, enabling frontend developers to rapidly debug pages or test various data scenarios. This article demonstrates how to build a local Mock service in three simple steps using JSON Server, requiring only a JSON file and no database setup!
Table of Contents
1. Prerequisites
Install Node.js
Install JSON Server
2. Building the Mock Service
Step 1: Create a Mock Data File (
db.json
)Step 2: Start the JSON Server
Step 3: Verify API Endpoints
3. Debugging and Extensions
Auto-Update Data
Debugging with Apidog
4. FAQ
Port Conflicts
Data Not Updating
5. Conclusion
I. Prerequisites
1. Install Node.js
Ensure Node.js is installed (download from https://nodejs.org).
Verify by running in terminal:
node -v && npm -v
If version numbers are displayed, installation is complete.
2. Install JSON Server
Open the terminal in your IDE (e.g., VS Code) and execute:
npm install -g json-server
If permission errors occur, try:
sudo npm install -g json-server
II. Building the Mock Service in 3 Steps
Step 1: Create a Mock Data File
Create a folder (e.g., mock-demo
) and add a db.json
file with the following content:
{
"users": [
{ "id": 1, "name": "John Doe", "age": 25 },
{ "id": 2, "name": "Jane Smith", "age": 30 }
],
"posts": [
{ "id": 1, "title": "First Post", "author": "John Doe" }
]
}