This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In


    CLI node modules

    Ben ClinkinbeardBen Clinkinbeard

    Many node modules provide a command line interface. In this lesson, we'll look at how to use them, as well as how to avoid npm install -g for "global" tools.



    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


    Man 1: 00:01 Some node modules provide a command line utility that can be used from the shell. Mocha is one of the things that does that. The way that it does that is in Mocha's package.json it lists, in this case, two files. Generally there's just going to be one.

    00:18 In this .bin identifier it lists out the files that it would like for MPM to make available from the command line. What MPM does in response is it creates this .bin folder within your node modules folder. It's regularly hidden from view. It then creates shortcuts to those files that were specified by Mocha.

    00:41 What you can then do to run that directly from the shell is to simply use that path to the local node modules folder and then .bin and then the name of the file. In this case we're just going to ask for the version. You can see there that the locally installed version of Mocha is 1.18.2.

    01:02 Now, a lot of tutorials and instructions that you'll see recommend to install things globally simply so that you can run them from the command line but that's actually entirely unnecessary. You can use the method that we just did to access the local path. You can use the scripts fields of your package.json which we'll cover later. Or the even easier way is to simply add that local path that we just used to your path environment variable.

    01:34 If you were to set to run this command. I'm not going to because I already have it. But if you were to add the ./node_modules./bin to your local path you can then simply use this file directly. I can just say Mocha-version and it's going to be that locally installed version.

    01:57 I can even say which Mocha and it will tell me that I'm point at that locally installed version.