3

In order to start my node server I have to run in different terminal tabs:

  1. redis-server

  2. mongod

  3. nodemon app/app.js

I have tried to make one script for those, in package.json like this:

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

However on npm start I receive the next error:

> 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
Raz Buchnik
  • 7,753
  • 14
  • 53
  • 96
  • The error is unrelated. an instance of redis is already running `TCP listening socket *:6379: bind: Address already in use` – aravindanve Dec 06 '18 at 11:24
  • Regarding your other problem, redis and mongo may require additional starup time. So running them in parallel may still result in your node app being unable to connect to the databases. – aravindanve Dec 06 '18 at 11:26
  • @AravindanVe any solution in your arsenal? – Raz Buchnik Dec 06 '18 at 12:13

1 Answers1

4

I would recommend two npm scripts. But if you really want it in one:

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

2>&1 should redirect stderr into stdout for both redis and mongo so you can errors in the output if any

aravindanve
  • 979
  • 7
  • 14