All notes
Npx

Intro

npx will check whether "command" exists in PATH, or in the local project binaries, and execute that. If "command" is not found, it will be installed prior to execution.

npmjs.com: npx.



#---------- Running a project-local bin
npm i -D webpack
npx webpack ...

#---------- One-off invocation without local installation
npm rm webpack
npx webpack -- ...
cat package.json
# ...webpack not in "devDependencies"...

#---------- -p, package
# -c <string> - Execute <string> inside an npm run-script-like shell environment, with all the usual environment variables available.
npx -p lolcatjs -p cowsay -c 'echo "your-cool-package@1.2.3" | cowsay | lolcatjs'
# "lolcatjs" prints a colorful art. "cowsay" prints a cow-say cartoon.
# ...
#  _____
# < your-cool-package@1.2.3 >
#  -----
#         \   ^__^
#          \  (oo)\_______
#             (__)\       )\/\
#                 ||----w |
#                 ||     ||

#---------- SHELL AUTO FALLBACK
# You can configure npx to run as your default fallback command when you type something in the command line with an @ but the command is not found.

npm@4 --version
# (stderr) npm@4 not found. Trying with npx...
# 4.6.1
asdfasdfasf
# zsh: command not found: asfdasdfasdf
# wcfNote: must with an @ in the command.

# To install permanently, add the relevant line below to your ~/.bashrc, ~/.zshrc, ~/.config/fish/config.fish
# For bash@>=4:
source <(npx --shell-auto-fallback bash)
# For zsh:
source <(npx --shell-auto-fallback zsh)
# For fish:
source (npx --shell-auto-fallback fish | psub)