# Install JSON Server Globally
npm install -g json-server
# #Install JSON Server Locally
npm install json-server
# Check JSON Server version
json-server --version
# Run JSON server
json-server --watch db.json
# Change the server PORT
json-server --watch db.json --port 4000
json-server --watch db.json
npm install -g json-server
#Install JSON Server
npm install -g json-server
#Start JSON Server
json-server --watch db.json
npm i --save-dev json-server
<add db.json file>
npx json-server --watch db.json
# to change port
npx json-server --watch db.json --port 8000
"json-server --watch db.json --port=5000"
JSON Server is a freely available Node package that can turn a JSON file on your computer into mock data storage. When JSON Server is running, we can send requests to get data from storage or add data to it, as though we were talking to a server with a database.
A huge benefit of JSON Server is that we don't have to spend much time setting the mock server up, allowing us to focus on developing the frontend of an application first.
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
const myObj = {name: "John", age: 31, city: "New York"};
const myJSON = JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;
json-server -p 8088 example.json