Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use a shorthand syntax for running multiple npm scripts with npm-run-all


    Running multiple scripts in series or in parallel can become very verbose. Using a tool such as npm-run-all can help reduce the amount of overhead you have to type in order to get the same behavior.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: To clean up our test script, we can leverage a nice NPM package called npm-run-all. You can install it with npm-i-npm-run-all and -d to save it to your dev dependencies. Now, we can update our test script by running npm-run-all, which allows you to reference your NPM scripts by their name, so you don't have to prepend to run in front of them.

    By default, the scripts will be run in series, so you don't need the ampersands, either. Now, we can save our code and run the NPM tests again and see that the scripts run in series, just as they did before. If we wanted these to run in parallel, we could come back and we could add the --parallel flag.

    Let's go ahead and move the mocha command to right before the style-int, so that we can see it run in parallel. NPM-run-all purportedly terminates the process when hitting Ctrl-C in parallel mode, so there's no need to append the weight command. To test this, let's add the watch flag at the end of our mocha script, so we can verify that's working as expected.

    Now, if we run our tests again, the scripts will run, and you'll notice the tests were ran last, even though it was the second script showing the parallel feature. At this point, if we opened one of our unit tests and were to save the file, it would rerun the tests, and yes it did.

    If we hit Ctrl-C, the process will actually terminate. We can verify this by saving the unit test file again, and yes, it has been terminated.