尝试同时 运行 Express 和 Vue 时出错

Error trying to running Express and Vue concurrently

我的 Vue 应用程序 运行s 在端口 8080 上。脚本设置:"serve": "vue-cli-service serve" 我用 yarn run serve.

启动它

我的 Express 服务器在端口 4000 上设置为 运行。我使用以下脚本以 yarn run dev 启动它:

"client-install": "yarn add --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "yarn start --prefix client",
"dev": "concurrently \"yarn run server\" \"yarn run client\""

当我尝试 运行 时,它显示错误:

查看该端口上已经 运行 的内容

netstat -a -n -o | find "4000"

TCP    127.0.0.1:4200         0.0.0.0:0              LISTENING       25160

获取 pid,例如如果 pid 是 25160 那么

tasklist /fi "pid eq 25160"

node.exe                     25160 Console                    1    399,528 K

然后您可以看到什么正在使用该端口,在本例中为节点。 还要检查这个项目:https://github.com/pietheinstrengholt/vue-express-boilerplate

使用名为 concurrently

的 npm 包解决了这个问题