NPX makes NPM nicer and even more useful

cowsay package output

First off, some context

Steps to install Angular CLI (Source: Angular CLI site)

1. Using binaries

.bin folder in node_modules

2. Using npm scripts

package.json file with a script

Welcome NPX

npm i -g npx

Executing a binary that is not installed in your computer

npx @angular/cli new my-app
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/*
npx <command> <command-options>

Executing a binary from your local project

npx @angular/cli serve
npx ng serve

Executing a binary installed globally

npx lt --port 4200

Executing a package with a specific version

npx create-react-app@2.0.0 my-react-app

Passing an argument to Node

npx --node-arg=--inspect vue-cli
npx: installed 239 in 9.533s
Debugger listening on ws://127.0.0.1:9229/ffcb736c-4847-4b7f-9c35-1c49b9573c65
For help, see:
https://nodejs.org/en/docs/inspector
Usage: vue <command> [options]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
init generate a new project from a template
list list available official templates
build prototype a new project
create (for v3 warning only)
help [cmd] display help for [cmd]

Executing a command with a npm-run like enviroment

"scripts": {"custom": "echo $npm_package_version"}
> npm run custom
> 1.0.0
> echo $npm_package_version
>
> npx -c 'echo $npm_package_version'
> 1.0.0

Executing a command using a different Node version

npx -p node@6 node index.js
npx -p node@6 npm run build
npx -p node@10.0.0 node index.js

Executing a command from a Git repo

npx jaireina/presentation
npx jaireina/presentation#colorful

Executing a code from a gist

npx https://gist.github.com/jaireina/aabcadcc51baf6f7ff904005ffb45e9c
? What's your name Vanessa
? Choose a text color black
? Choose a background color yellow

Conclusion

npx cowsay “That’s all for today. Any feedback or cowmments are appreciated. Thank you.”

Conclusion

npx cowsay “That’s all for today. Any feedback or cowmments are appreciated. Thank you.”

Software Engineer - VP Architect @Digitas

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