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.


    Create a custom npm script

    Elijah ManorElijah Manor

    A lot of the power behind npm scripts is creating custom scripts that are outside the basic set that npm natively understands. In this lesson we will install the ESLint node package, create a new eslint npm script, briefly discuss about environment variables and how npm knows where to find your binary, and then execute our custom script from the command line.



    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




    Instructor: Let's create a new custom npm script called eslint. First, we'll come down to our tests and make a new entry for eslint. Here, we'll call eslint.

    We'll pass the catch flag so it won't re-lint things that haven't changed. We'll pass the fix flag, which will auto-fix certain rules that have simple solutions. Then we'll tell eslint to lint all the files in the current path.

    Many developers don't like to have many globally installed node modules. You might be tempted to reference the locally installed version of eslint by referencing the node_modules bin folder, or you might be inclined to use the npm bin command.

    However, npm does provide many environment variables for you. If you type "npm run environment," it'll list all the environment variables that it adds or updates.

    If we run that again and search for the path, then we'll see that npm adds our local bin folder for us, which means we can remove all the additional path information. We'll use the local version.

    Now we can go to our terminal and type "npm run-script eslint," or, for short, we could just say, "npm run eslint." That will run our new custom npm script.