DEV Community

Cover image for How to run multiple npm scripts with npm-run-all
Dany Paredes
Dany Paredes

Posted on • Updated on

How to run multiple npm scripts with npm-run-all

Sometimes we need to run a fake API with JSON-Server and SPA at same time.

We need to run each command one for our spa vue serve or ng serve and other for json-server json-server /db.json

One solution is with concatenating each command using && but if tomorrow we need to start another program the line will be look like:

npm run lint && npm run build && npm run api && npm run whereverthing :P
Enter fullscreen mode Exit fullscreen mode

Then I found npm-run-all is a node package, it allows us to run all scripts defined in npm in sequential or parallel each one in parallel.

First install npm-run-all.

npm install -g npm-run-all
Enter fullscreen mode Exit fullscreen mode

The define a new option into our script area, like all and call the npm-run-all with type of execution --parallel or secuential (by default) and scripts names.

"scripts": {
        "serve": "vue-cli-service serve",
        "build": "vue-cli-service build",
        "lint": "vue-cli-service lint",
        "api": "json-server src/db.json",
        "all": "npm-run-all --parallel serve api"
    },
Enter fullscreen mode Exit fullscreen mode

Happy NPM!

Photo by Matúš Kovačovský on Unsplash

Top comments (0)