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
使用
想法或问题?在 GitHub Issue 下方参与讨论
去评论