How to Run Multiple NPM Scripts in Parallel?
Last Updated :
05 Jul, 2024
Running multiple npm scripts in parallel can be particularly useful when you need to perform several tasks simultaneously, such as starting a server, running a build process, and monitoring file changes. This can save time and streamline your development workflow. Here’s a comprehensive guide on how to run multiple npm scripts in parallel.
Method 1: npm-run all package
We can use the" npm-run all" package to run different scripts at the same time. First, we have to install the package itself by using the command.
npm install npm-run-all — save-dev
After installation of the package we have to navigate to the package.json file of the project, and we can see that there are two operations listed inside the "scripts" i.e "start" & "build" that we need in order to host the project on the server and to run the build operation simultaneously.

Now, our next step would be to open up a terminal on Mac or command prompt on Windows and "cd" into the project directory and type the command "./node_modules/.bin/npm-run-all build start " and press Enter.
In the local installation case which we did, npm-run-all will be installed into our project's node_modules directory. PATH environment variable does not include there, so we have to use
./node_modules/.bin/npm-run-all
(or $(npm bin)/npm-run-all) to run npm-run-all command.
Output:
Build operation executed successfully
The app is hosted successfully on the serverBrowser Output: Therefore, we can now see that our app is successfully hosted on a local server, and the build operation executed perfectly with the help of a single package "npm-run-all".

Method 2: Using Concurrently package
In this approach, we will be using the Concurrently package . Using this package we can combine different script commands such as "npm run start" and "npm run build " into a single script and then run it in the command line.
First, install the package in your project directory using this command :
npm install concurrently --save
Again after installation of the package we have to navigate to the package.json file of the project, and we can see that there are two operations listed inside the "scripts" i.e "start" & "build" that we need in order to host the project on the server and to run the build operation simultaneously. Now we have to include a dev script inside the scripts in the package.json file which will hold our different commands combined.

Note: With --kill-others switch, all commands are killed if one dies. We can follow this to create our own dev script :
"dev": "concurrently \"command1 arg\" \"command2 arg\""
Now we can simply run the whole command by simply using:
npm run dev

Method 3: Using concurrently
The concurrently
package is another powerful tool to run multiple commands simultaneously. It also provides better output management by prefixing logs with the script name.
Install concurrently
npm install concurrently --save-dev
Configure Your package.json,
Add a script to run commands concurrently
"scripts": {
"script1": "echo 'Running script 1' && sleep 1",
"script2": "echo 'Running script 2' && sleep 2",
"script3": "echo 'Running script 3' && sleep 3",
"parallel": "concurrently \"npm run script1\" \"npm run script2\" \"npm run script3\""
}
Run Scripts in Parallel, Execute the parallel
script to run the commands concurrently
npm run parallel
Similar Reads
How to send Multiple Requests at same time in Postman ?
Postman is a popular API development tool that allows us to design, test, document, and debug APIs more efficiently. This article is all about sending multiple requests at the same time in Postman. Advantages of sending multiple requests at same time in Postman :Efficiency: It saves time and improve
1 min read
How to Run Multiple Versions of Node.js ?
Usually, we work on different versions for our Node.js project and it's hard to manage them, but fortunately, there is a tool called NVM(node version manager) which helps to manage your node version and switch between them according to your projects. Install NVM Module: You can install the nvm modul
2 min read
Introduction to NPM scripts
NPM is a Node Package Manager. It is the world's largest Software Registry. This registry contains over 800,000 code packages. Many Open-source developers use npm to share software. Many organizations also use npm to manage private development. "npm scripts" are the entries in the scripts field of t
2 min read
How to Update Local Package in NPM?
Updating the local packages in NPM is a common task for the developers. Whether it is for bug fixes, new features, or security patches. Keeping your dependencies up to date is essential. These are the following approaches to updating the local package in NPM:Table of ContentUpdate to the Latest Stab
4 min read
How To Run Many Parallel HTTP Requests Using Node.js?
Node.js is designed to efficiently handle multiple client requests through its event-driven architecture. This architecture allows Node.js to process requests asynchronously, making it ideal for high-performance, scalable applications. When Node.js receives multiple client requests, it places them i
5 min read
How to Install GIT by NPM Packages?
Git is a library for git written in Node.js which allows for the manipulation of git repositories by the Node.js application. Git (npm), not to be confused with GIT, the version control software is a Node.js port of the now-defunct Git project. It is fairly synchronous as-is, and it allows the devel
2 min read
How to Force an NPM Package to Install?
Forcing an NPM package to install can be necessary in cases where the dependencies of a package are in conflict or when you need to override existing constraints or force the installation of a specific version. Forcing an NPM package to install refers to using specific commands to bypass version con
3 min read
How to use External Modules and NPM in a project ?
Need for External Modules: For a large JavaScript application, it becomes difficult and messy to write the whole code in just one JavaScript file. This is where CommonJS comes into the picture and this CommonJS format defines a module format that can be used up for breaking your JS application into
3 min read
How to compile multiple Typescript files into a single file ?
In this article, we will learn how to compile multiple Typescript files into a single file. There are two approaches that can be followed here: Approach 1: Compiling multiple Typescript files into a single JavaScript file. We simply use the following syntax: Syntax: tsc --out outputFile.js typeScrip
4 min read
How to Run Synchronous Queries using sync-sql Module in Node.js ?
The sync-sql module is designed to make synchronous queries to the database. Since normal SQL queries are asynchronous in node.js but if you want to run it synchronously, then it is possible using this module. In synchronized SQL, the result set is returned when the query is executed. Note: Do not u
2 min read