JS-JMS-WEB
JS-JMS-WEB

Reputation: 2625

npm scripts not working as intended

I'm trying to use npm scripts as 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 running start (http-server). But I'm only able to run one at a time. If I type npm start only json-server runs. Is it possible to run two servers in single command?

Upvotes: 3

Views: 730

Answers (1)

Gerald
Gerald

Reputation: 23499

You could 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 npm start will run start-json and start-http concurrently.

Upvotes: 4

Related Questions