Execute Code from a Remote GitHub Branch with npx

Elijah Manor
InstructorElijah Manor

Share this video with your friends

Send Tweet
Published 3 years ago
Updated 2 years ago

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.

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

[00:15] 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.

[00:42] 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.

[01:07] 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.

Paavo Muranen
Paavo Muranen
~ 3 years ago

I must say that this course has been seamless experience and especially this module made me smile. I really recommend taking e.g. this course as one of the first ones when aiming towards react because it helps you to verify your local setup and gives confidence over the command line mastery. Actually I really hope you make module for the "geeky sig" !