🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
05 : 09 : 29 : 43
1×
Become a member
to unlock all features
Autoplay

    Execute Code from a Remote GitHub Branch with npx

    Elijah ManorElijah Manor
    npmnpm
    >=5.2.0

    In this session we will show how you can use npx to pull and execute code from a GitHub repository. If you need even more control, you can target a specific branch of your repository to execute.

    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
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: I have a CLI package on NPM called ElijahManor that prints out information about myself. It's like a really geeky digital business card. Anyway, if I run ElijahManor, you'll notice that I don't have it installed globally.

    I can temporarily install it and run it with npx ElijahManor. However, the output is somewhat boring. It's just JSON written to the console. Let's go to our local repo, and navigate to GitHub with npm repo, where you'll see that I've been working on a separate branch called interactive that I'd like to run locally with NPX.

    NPX will recognize repos from GitHub, and you even execute individual branches. If I type npx ElijahManor/ElijahManor#interactive, it'll now temporarily download my branch, and run it locally. As you could tell, this version looks a bit more interesting, and you could interact with the options in order to visit various URLs, like my Twitter, for example.

    Since I had the repo cloned locally on my computer, I could have run the project from that directory. Using NPX, I could run this experimental branch on any computer, even if the code wasn't already on that machine. Pretty cool.