Npm scripts not working as expected

I am trying to use npm scripts like below:

"scripts": {
    "test": "karma start karma.conf.js",
    "prestart": "json-server --watch db.json",
    "start": "http-server -a localhost -p 8000 -o -c-1"
  },  

      

I want to use prestart

(json-server) before starting start

(http-server). But I can only run one. If I type npm start

, only is executed json-server

. Is it possible to run two servers in one command?

+3


source to share


1 answer


You can do something like this:

"scripts": {
    "test": "karma start karma.conf.js",
    "start-json": "json-server --watch db.json",
    "start-http": "http-server -a localhost -p 8000 -o -c-1",
    "start": "npm run start-json & npm run start-http"
  }, 

      



Now it npm start

will run start-json

both start-http

at the same time.

+4


source







All Articles