json-服务器未显示 URL 的 JSON 数据

json-server not showing URL for JSON data

我正在与 json-server 合作。我已经用 npm install -g json-server 安装了它,正在使用

观看
json-server --watch db.json

我在应用程序文件夹中添加了 db.json 文件,其中包含以下数据

{
    "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"
      }
    ]
  }

但只有 http://localhost:3000/ 有效。它显示

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 无效。我该如何解决这个问题?

第一次尝试 运行 json-server,如果找不到提供的源,load.js 会为您写出默认示例:


> json-server --观看 db.json


  \{^_^}/ 你好!

  正在加载 db.json
  <b>糟糕,db.json 似乎不存在
  使用一些默认数据 </b> 创建 db.json

  完毕

  资源
  http://localhost:3000/帖子
  http://localhost:3000/评论
  http://localhost:3000/配置文件

  家
  http://本地主机:3000

在随后的 运行 秒中,因为文件现在存在,服务器似乎启动正常,但没有使用您认为的 db.json 文件。出于这个原因,这似乎有点不正常,我 opened a PR 要求明确请求此行为。

db.json应该设置在根目录下吧?你表示你把你的放在应用程序文件夹中。

最初 JSON-server 必须从根文件夹启动。 例如:如果您使用的是 VS 代码编辑器,请单击包含 JSON 格式数据的文件夹,然后右键单击该文件夹并在集成终端中打开它,然后尝试:> json-server --watch db.json 它将正常工作。

如果直接调用Json-server,会初始化localhost:3000

上的默认数据