Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

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

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

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

    Elijah ManorElijah Manor

    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.

    npmnpm
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    Instructor: 00:01 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.

    00:28 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.

    00:47 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.

    01:09 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.

    01:27 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.

    Discuss

    Discuss