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.