loading...

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

danywalls profile image Dany Paredes ・1 min read

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

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

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"
    },

Happy NPM!

Posted on by:

danywalls profile

Dany Paredes

@danywalls

ex .NET guy, my last years building solutions with Vue, Angular, Sass, and Typescript.

Discussion

markdown guide