首页 > 解决方案 > 同时运行两个 npm 命令

问题描述

我已经设置json-server并成功运行,port-3000然后运行npm start它在其他端口上运行3001

但我想同时运行两者。我试过并发但没有用。

当我执行此命令时:

$ concurrently "npm start" "json-server --watch ./topPanelData.json"

错误信息:

错误信息

标签: reactjscreate-react-appjson-server

解决方案


通过这些步骤解决的问题:

  1. 使用以下密钥创建json-server.json以在不同端口上运行服务器。

    { "port": 4000 }

  2. 更新启动脚本package.json

    "start": "concurrently \"react-scripts start\" \"json-server ./topPanelData.json\""

  3. 只需运行$ npm start它会同时在不同的端口上执行

    json 服务器: http://localhost:4000/topPanelData

    反应应用程序: http://localhost:3000/


推荐阅读