json-server not showing URL for JSON data

Viewed 2763

I am working with json-server. I have installed it with npm install -g json-server and am watching using

json-server --watch db.json

I have added db.json file in app folder with below data

{
    "product": [
      {
        "userId": 1,
        "firstName": "Krish",
        "lastName": "Lee",
        "phoneNumber": "123456",
        "emailAddress": "krish.lee@learningcontainer.com"
      },
      {
        "userId": 5,
        "firstName": "jone",
        "lastName": "mac",
        "phoneNumber": "111111111",
        "emailAddress": "jone.mac@learningcontainer.com"
      }
    ]
  }

but only http://localhost:3000/ is working. It shows

Congrats!
You're successfully running JSON Server
✧*。٩(ˊᗜˋ*)و✧*。

Resources
/posts 1x
/comments 1x
/profile object
To access and modify resources, you can use any HTTP method:

GET POST PUT PATCH DELETE OPTIONS

undefined
Documentation
README

To replace this page, create a ./public/index.html file.

http://localhost:3000/product is not working. How can I fix this issue?

3 Answers

The first time you try to run json-server, if it can't find the supplied source, load.js writes out the default example for you:


> json-server --watch db.json


  \{^_^}/ hi!

  Loading db.json
  Oops, db.json doesn't seem to exist
  Creating db.json with some default data

  Done

  Resources
  http://localhost:3000/posts
  http://localhost:3000/comments
  http://localhost:3000/profile

  Home
  http://localhost:3000

On subsequent runs, because the file now exists, the server seems to be starting up just fine but isn't using the db.json file you think it is. For that reason, this seems like a bit of a misfeature, I've opened a PR to require this behaviour to be explicitly requested.

db.json is supposed to be set up in in the root folder? you indicated you put yours in the app folder.

At initial the JSON-server must be started from the root folder. ex : if you are using VS code editor click on the folder that consist the data in JSON format and right click on that folder and open it in integrated terminal and try : > json-server --watch db.json and it will be working fine.

In case of directly calling the Json-server, it will initialise the default data on localhost:3000

Related