Introducing npx: an npm package runner

Using locally-installed tools without npm run-script

Installing cowsay as a local devDependency and running it with `$ npx cowsay`

Executing one-off commands

`$ npx create-react-app my-cool-new-app` installs a temporary create-react-app and calls it, without polluting global installs or requiring more than one step!

Run commands with different Node.js versions

`npx -p node@<version> node -v` can be used to do one-off runs of node versions.

Developing npm run-scripts interactively

`$ npx -p cowsay -p lolcatjs -c ‘echo “$npm_package_name@$npm_package_version” | cowsay | lolcatjs’` installs both cowsay and lolcatjs, and gives the script access to a slew of `$npm_` variables from run scripts.

Share gist-based scripts with friends and loved ones!

Bonus Round: shell auto-fallback

Putting the npx auto fallback in .zshrc means you can do `$ ember-cli@latest …` without referencing npx at all!

Do It Live!

You can get npx now by installing npm@5.2.0 or later — or, if you don’t want to use npm, you can install the standalone version of npx! It’s totally compatible with other package managers, since any npm usage is only done for internal operations. Oh, and it’s available in 10 different languages, thanks to contributions by a bunch of early adopters from all over the world, with --help and all system messages translated and automatically available based on system locale! There’s also an awesome-npx repo with examples of things that work great with npx!

 by the author.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kat Marchán

Kat Marchán

3K Followers

npm CLI team’s green-haired digital dryad. Boricua. Queer af. @wealljs admin. http://pronoun.is/they?or=she