Concurrent Scripts

· 163 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. What happens when each process is dumping data into the console? What happens if one of the scripts fails?

To solve these issues, concurrently helps us start multiple commands.

npm install concurrently --save

Concurrently accepts multiple arguments enclosed in quotes and separated by spaces. It will run each command and stop 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 also use concurrently globally for other terminal commands. Install it globally:

npm install -g concurrently

Then use it from the terminal:

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