Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm scripts not working as intended

Tags:

npm

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?

like image 965
JS-JMS-WEB Avatar asked Dec 29 '25 22:12

JS-JMS-WEB


1 Answers

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.

like image 199
Gerald Avatar answered Jan 01 '26 18:01

Gerald