"start-client": "cross-env NODE_ENV=生产 Node ./server/index.js",
"start-api": "cross-env NODE_ENV=生产 Node ./server/api/index.js",
"start-pro": "同时\"npm run start-client\"\"npm run start-api\""
npm run start-pro
在Liunx系统上运行成功,但我关闭 session 然后服务器结束。
当我运行 npm run start-pro &
命令时也可以,当我关闭 session 时出现 503 错误。
当我执行nohup npm run start-pro &这个命令的时候,在项目的根目录中出现了nohup.output的文件,里面记录了错误:
执行nohup npm run start-pro &
命令时出现错误,错误在nohup.out
文件中:
p2@0.1.0 start-pro /website/pgyer concurrently "npm run start-client" "npm run start-api"
events.js:160 throw er; // Unhandled 'error' event ^
Error: EBADF: bad file descriptor, read at Error (native) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! p2@0.1.0 start-pro:
concurrently "npm run start-client" "npm run start-api"
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the p2@0.1.0 start-pro script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-07-18T00_30_14_968Z-debug.log
再试一次!现在先执行 nohup npm run start-api &
就成功了!然后执行 nobup npm run start-client &
命令也成功了!
So,i want to kown,how can i do one command to start two server:
start-client
andstart-api
,and i close the session the server is ok?
最佳答案
您可以使用并发安装它
同时 npm install -g
或者如果您从 npm 脚本中使用它:
npm同时安装--save
concurrently "command1 arg" "command2 arg"
欢迎访问https://www.npmjs.com/package/concurrently如果你想同时使用 else https://www.npmjs.com/package/npm-run-all如果你擅长使用npm-run-all
要在后台运行命令,请创建 app.js 并使用 npm 命令行库 https://www.npmjs.com/package/node-command-line
function runMultipleCommandWithoutWait() {
Promise.coroutine(function *() {
var commands = ["node --version","npm --version"];
for(var i=0; i < commands.length; i++) {
cmd.run(commands[i]);
}
console.log('Executed your command :)');
})();
}
关于node.js - 我在Linux系统上实现了多个npm命令,所有这些命令都是使用nodejs启动一个网站,让它们在后台运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51394724/