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

    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.

    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 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.

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

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

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

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

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

    Discuss

    Discuss