---
title: "How to run multiple npm scripts with npm-run-all"
date: "2020-08-09"
slug: "how-to-run-multiple-npm-scripts-with-npm-run-all"
author: "Dany Paredes"
canonical: "https://danywalls.com/how-to-run-multiple-npm-scripts-with-npm-run-all"
description: "Sometimes we need to run a fake API with JSON-Server and SPA at the same time. We need to run each command, one for our spa vue serve or  ng serve and the other for json-server json-server /db.json  One solution is with concatenating each command usi..."
---

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

We need to run each command, one for our spa _vue serve_ or  _ng serve_ and the 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 look like:
```bash
npm run lint && npm run build && npm run API && npm run wherever thing :P
```

Then I found [npm-run-all](https://www.npmjs.com/package/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*.
```bash
npm install -g npm-run-all
```
The define a new option into our script area, like **all**, and call the npm-run-all with the type of execution --parallel or sequentially (by default) and scripts names.

```json
"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!

Photo by <a href="https://unsplash.com/@ohamko?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Matúš Kovačovský</a> on <a href="https://unsplash.com/s/photos/multiple?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

