Concurrent Scripts

· 167 words · 1 minute read

Some time ago I shared a set of useful Control Operators to use in the terminal and NPM scripts. This time I’ll show you a better solution for concurrent scripts.

The old one does the job well, but what happens when each process is dumping data into the console? or what happens if one of the scripts fails?

To solve these issues, concurrently help us to start multiple commands.

npm install concurrently --save

Concurrently accepts multiple arguments closed by quotes and separated by spaces. It will run each command and will end if one fails.

For instance, following the same example as the Control Operators post:

  "scripts": {
    "build": "concurrently \"npm run build:web\" \"npm run build:admin\""
    "build:web": "...."
    "build:admin": "..."
  }

I can tell you, this is terrific, you will notice when one of the scripts fails.

You can use concurrently globally too, for other terminal commands. Install it globally.

npm install -g concurrently

And use it from the terminal.

concurrently "npm run build:web" "npm run build:admin"