JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源。

安装json-server

  全局模式下打开小黑窗,输入 npm i json-server -g

 

启动 json-server

json-server可以直接把一个json文件托管成一个具备全RESTful风格的API,并支持跨域、jsonp、路由订制、数据快照保存等功能的 web 服务器。

准备好一个存放的文件夹,里面备好需要的json文件,在此文件夹下运行小黒窗(shift+右键——》在此处打开命令窗口)

  输入 json-server  文件名.json

 

json-server 的相关启动参数

 

语法:json-server [options] <source>

参数 简写 默认值 说明
--config -c 指定配置文件 [默认值: "json-server.json"]
--port -p 设置端口 [默认值: 3000] Number
--host -H 设置域 [默认值: "0.0.0.0"] String
--watch -w Watch file(s) 是否监听
--routes -r 指定自定义路由  
--middlewares -m 指定中间件 files [数组]
--static -s Set static files directory 静态目录,类比:express的静态目录
--readonly --ro Allow only GET requests [布尔]  
--nocors --nc Disable Cross-Origin Resource Sharing [布尔]  
--no gzip , --ng Disable GZIP Content-Encoding [布尔]  
--snapshots -S Set snapshots directory [默认值: "."]  
--delay -d Add delay to responses (ms)  
--id -i Set database id property (e.g. _id) [默认值: "id"]  
--foreignKeySuffix -- fks Set foreign key suffix (e.g. _id as in post_id) [默认值: "Id"]
--help -h 显示帮助信息 [布尔]
--version -v 显示版本号 [布尔]

 

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-05-17
  • 2022-01-11
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2021-04-10
  • 2021-07-24
  • 2022-01-04
  • 2021-11-20
  • 2021-10-11
相关资源
相似解决方案