繁体   English   中英

命令 json-server --watch db.json 不工作 - 它返回“'json-server' 命令未找到”

[英]Command json-server --watch db.json is not working - it returns"'json-server' command not found"

我设置了一个 JSON 文件作为小练习数据库,但是我无法运行服务器。

我已经尝试在全球和本地安装(并重新安装)json-server npm install -g json-servernpm install json-server然后运行json-server --watch db.json ,但它不起作用。

我还尝试在 package.json 文件中设置脚本"load": "json-server --watch db.json"并运行脚本node load

但似乎没有任何效果,我不断收到回复消息:

“找不到‘json-server’命令”

或者,用葡萄牙语:

“'json-server' não é reconhecido como um comando interno ou externo,um programa operável ou um arquivo em lotes”。

我怎样才能解决这个问题?

尝试:

npx json-server --watch db.json

检查这是否可以帮助您。

打开 git bash(假设您在本地机器上有)并执行以下命令: alias json-server="<..../node_modules/.bin/json-server.cmd>" ---> IGNORE <, >符号和 .... 是 node_modules 文件夹所在的位置

然后运行json-server --watch db.json

解决方案:对于 Linux:

  1. 首先,运行此命令全局安装json-server

    sudo npm install -g json-server

  2. 移动到您的本地文件夹(如 my-app)并运行此命令

    npm install json-server

  3. 在同一文件夹中打开一个新终端

    json-server --watch db.json --port 3004

我在我的package.json文件中添加了用于运行 json-server 的脚本,如下所示:

 "server": "json-server db.json --watch --port 5000"

并尝试像这样运行它:

npm run server

它可以正常工作,除非服务器没有被监视,除非每次进行更改时我都必须手动结束并运行 json 服务器命令。

为我修复它的是直接在 bash 终端(在应用程序根目录下)中运行命令。

所以运行:

json-server db.json --watch --port 5000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM