返回博客列表

Json-Server库

2026-01-29
1 min read
guide

本地启用 文档 可以用json也可以用json5。 然后就在本地启动了一个数据库api 使用 - http://localhost:3000/posts?title=another - http://localhost:3000/posts/:id

pnpm add json-server

本地启用

文档

  • 可以用json也可以用json5。

npx json-server db.json5

json
{
  //  博客
  "posts": [
    {
      "id": "1",
      "title": "a title",
      "views": 100
    },
    {
      "id": "2",
      "title": "another",
      "views": 200
    }
  ],
  "comments": [
    {
      "id": "1",
      "text": "a comment about post 1",
      "postId": "1"
    },
    {
      "id": "2",
      "text": "another comment about post 1",
      "postId": "1"
    }
  ],
  "profile": {
    "name": "typicode"
  }
}

然后就在本地启动了一个数据库api

bash
JSON Server started on PORT :3000
Press CTRL-C to stop
Watching db.json5...

♡( ◡‿◡ )

Index:
http://localhost:3000/

Static files:
Serving ./public directory if it exists

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

使用

返回博客列表
最后更新于 2026-01-29
想法或问题?在 GitHub Issue 下方参与讨论
去评论