为了启动我的 Node 服务器,我必须在不同的终端选项卡中运行:

  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 

请您参考如下方法:

我会推荐两个 npm 脚本。但如果你真的想要它合二为一:

{ 
    ... 
    "start": "redis-server 2>&1 & mongod 2>&1 & nodemon app/app.js" 
} 

2>&1 应将 redis 和 mongo 的 stderr 重定向到 stdout,以便您可以在输出中出现错误(如果有)


评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!