1. npm init
2. npm install json-server --save OR npm install --save json-server
3. Modify package.json file
{
"name": "ram-pukar-json-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json --port 3004",
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.16.1"
}
}
NOTE: "json:server": "json-server --watch db.json"
4. create db.json file
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}
5. Run CMD
npm run json:server
Source: https://www.npmjs.com/package/json-server
---------------------------------------------------
Add this url : json-server http://jsonplaceholder.typicode.com/
{
"name": "ram-pukar-json-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json --port 3004",
"json:server:remote": "json-server http://jsonplaceholder.typicode.com/db --port 3004"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.16.1"
}
}
0 comments:
Post a Comment