DEV Community

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

Posted on • Edited on

3 1

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

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay