How to Run Multiple Npm Scripts in Parallel?

Better Stack Team
Updated on April 4, 2024

To run multiple npm scripts in parallel, you can use a task runner like concurrently or npm-run-all. These tools allow you to execute multiple commands concurrently, making it easy to run multiple npm scripts simultaneously.

Using concurrently

  1. Install concurrently globally (if not already installed):

     
    npm install -g concurrently
    
  2. Update your package.json to include scripts that you want to run concurrently:

     
    {
      "scripts": {
        "start": "node server.js",
        "build": "webpack",
        "lint": "eslint src",
        "dev": "concurrently \\"npm run start\\" \\"npm run build\\" \\"npm run lint\\""
      }
    }
    
  3. Run the concurrent npm scripts:

     
    npm run dev
    

Using npm-run-all

  1. Install npm-run-all globally (if not already installed):

     
    npm install -g npm-run-all
    
  2. Update your package.json to include scripts that you want to run concurrently:

     
    {
      "scripts": {
        "start": "node server.js",
        "build": "webpack",
        "lint": "eslint src",
        "dev": "npm-run-all --parallel start build lint"
      }
    }
    
  3. Run the concurrent npm scripts:

     
    npm run dev
    

Both concurrently and npm-run-all provide options for running scripts in parallel or in a specific sequence. Adjust the scripts in your package.json file according to your project's needs.

Choose the tool that best fits your requirements and integrates well with your project.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github