npm脚本可同时运行redis-server,mongod和nodemon

时间:2018-12-06 11:13:03

标签: node.js npm package.json npm-scripts npm-start

要启动我的节点服务器,我必须在不同的终端选项卡中运行:

  1. redis-server

  2. mongod

  3. nodemon app/app.js

我试图在package.json中为这些脚本制作一个脚本,如下所示:

"start": "redis-server && mongod && nodemon app/app.js"

但是在npm start上,我收到下一个错误:

> server@1.0.0 start /Users/razbuchnik/Projects/taxi4you/server
> redis-server && mongod && npm run dev

790:C 06 Dec 13:11:32.993 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
790:C 06 Dec 13:11:32.994 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=790, just started
790:C 06 Dec 13:11:32.994 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
790:M 06 Dec 13:11:32.996 # Creating Server TCP listening socket *:6379: bind: Address already in use
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server@1.0.0 start: `redis-server && mongod && npm run dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the server@1.0.0 start 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!     /Users/razbuchnik/.npm/_logs/2018-12-06T11_11_33_004Z-debug.log

1 个答案:

答案 0 :(得分:0)

我建议两个npm脚本。但是,如果您真的想要它:

label

{ ... "start": "redis-server 2>&1 & mongod 2>&1 & nodemon app/app.js" } 应该将Redis和mongo的2>&1重定向到stderr中,这样您就可以在输出中出现错误