My NPM package has the following scripts to
- Start MongoDB.
- Build an angular app and having it watched with any changes.
Start an express server using nodemon.
"scripts": { "start_db": "mongod", "start_client": "ng build --output-path ./server/public/ --watch", "start_server": "nodemon --inspect -w server ./server/server.js", "start_all": "concurrently \"mongod\" \"nodemon --inspect -w server ./server/server.js\" \"ng build --output-path ./server/public/ --watch\""}
I want to do them all using a single command, so I add a script "start_all" and use concurrently.
However, when the express server starts, mongodb is not yet started and errors report.
[1] 2019-07-15 13:36:54 - error - Connection to DB failed. MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017] [1] at Pool. (/repository/dashboard-js/node_modules/mongodb-core/lib/topologies/server.js:431:11) [1] at Pool.emit (events.js:198:13) [1] at connect (/repository/dashboard-js/node_modules/mongodb-core/lib/connection/pool.js:557:14) [1] at makeConnection (/repository/dashboard-js/node_modules/mongodb-core/lib/connection/connect.js:39:11) [1] at callback (/repository/dashboard-js/node_modules/mongodb-core/lib/connection/connect.js:261:5) [1] at Socket.err (/repository/dashboard-js/node_modules/mongodb-core/lib/connection/connect.js:286:7) [1] at Object.onceWrapper (events.js:286:20) [1] at Socket.emit (events.js:198:13) [1] at emitErrorNT (internal/streams/destroy.js:91:8) [1] at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) [1] at process._tickCallback (internal/process/next_tick.js:63:19) [1] [nodemon] app crashed - waiting for file changes before starting...
Are there any way to fix this issue? For example, can I configure concurrently so that it only executes "start_client" and "start_server" after "start_db" completes?