npm scripts
parallel execution
Node.js
JavaScript development
coding tips

How can I run multiple npm scripts in parallel?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Running multiple npm scripts in parallel is a common need during development. Typical examples include starting a backend server while a frontend watcher rebuilds assets, or running separate build pipelines for CSS and JavaScript at the same time.

Plain npm does not provide a rich built-in “run these scripts in parallel and manage their output” feature. In practice, developers usually choose either a shell-level background operator for simple local use or a helper package such as concurrently or npm-run-all for cross-platform projects.

The Simplest Approach: Shell Operators

On Unix-like shells, you can chain commands with &:

json
1{
2  "scripts": {
3    "watch:js": "webpack --watch",
4    "watch:css": "sass --watch src:dist",
5    "dev": "npm run watch:js & npm run watch:css"
6  }
7}

This works, but it has drawbacks:

  • it is shell-dependent
  • it behaves differently on Windows environments
  • output from both commands can become messy
  • process shutdown is not coordinated well

For one-person local scripts, it may be enough. For shared tooling, it is usually not the best choice.

Using concurrently

concurrently is a popular option because it is cross-platform and gives you readable prefixed output.

Install it as a development dependency:

bash
npm install --save-dev concurrently

Then define a combined script:

json
1{
2  "scripts": {
3    "watch:js": "webpack --watch",
4    "watch:css": "sass --watch src:dist",
5    "dev": "concurrently \"npm run watch:js\" \"npm run watch:css\""
6  }
7}

Now run:

bash
npm run dev

This starts both scripts together and makes the output easier to follow.

A useful feature is coordinated shutdown. If one process fails, you can tell concurrently to terminate the others too.

json
1{
2  "scripts": {
3    "dev": "concurrently --kill-others \"npm run api\" \"npm run web\""
4  }
5}

Using npm-run-all

Another widely used option is npm-run-all, which supports both sequential and parallel orchestration.

Install it:

bash
npm install --save-dev npm-run-all

Then use its parallel mode:

json
1{
2  "scripts": {
3    "watch:js": "webpack --watch",
4    "watch:css": "sass --watch src:dist",
5    "dev": "npm-run-all --parallel watch:js watch:css"
6  }
7}

This is concise and especially nice when you want to reference several named npm scripts instead of repeating full commands.

Choosing Between Them

A practical rule is:

  • use shell & only for quick local experiments
  • use concurrently when readable output and process control matter
  • use npm-run-all when you want to orchestrate many named scripts in sequence and parallel combinations

Neither package changes what your scripts do. They only make process orchestration cleaner and more portable.

A Realistic Example

Suppose you have a frontend and backend in one project.

json
1{
2  "scripts": {
3    "api": "node server.js",
4    "web": "vite",
5    "dev": "concurrently --kill-others \"npm run api\" \"npm run web\""
6  }
7}

One npm run dev command now starts the whole local environment.

That is often the difference between a toolchain people actually use and one they avoid because it needs three separate terminals.

Common Pitfalls

A common mistake is assuming npm run a & npm run b is portable everywhere. It depends on the shell, so it is not a safe default for team projects.

Another mistake is ignoring process shutdown behavior. If one watcher fails and the other keeps running, developers may think the system is healthy when it is not.

People also forget to quote commands properly when using concurrently, especially in package.json where quoting rules matter.

Finally, do not solve every workflow problem with more parallelism. Some scripts depend on outputs from others and should run sequentially instead.

Summary

  • npm scripts can be run in parallel, but plain npm offers limited orchestration by itself.
  • Shell & works for simple local cases but is not reliably cross-platform.
  • 'concurrently is a strong choice when you want readable logs and coordinated shutdown.'
  • 'npm-run-all --parallel is useful when orchestrating named npm scripts.'
  • Pick the tool based on portability, output clarity, and whether your tasks are truly independent.

Course illustration
Course illustration

All Rights Reserved.