OnCallReadyStart learning

npx: Run a command from a local or remote npm package

npx -- <pkg>[@<version>] [args...]
npx --package=<pkg>[@<version>] -- <cmd> [args...]
npx -c '<cmd> [args...]'

What it does

Runs a command from an npm package, either one installed in the local project or fetched into the npm cache, in a context like npm run. When the package is not a local dependency, npx asks before installing it ("Need to install the following packages: ... Ok to proceed? (y)"); --yes or --no answers in advance, and the prompt is skipped when there is no terminal.

Options you will use

--package=<pkg>, -p <pkg>
The package(s) to install; the command to run follows.
-y, --yes
Install without asking.
--no
Refuse to install; fail if the package is not already available.
-c <cmd>
Run a shell command with the package binaries on PATH.

Examples

$ npx @techdocs/cli generate

run the TechDocs CLI without installing it globally

$ npx --yes @techdocs/[email protected] --version

a pinned version, no prompt

Gotchas

Taught in

Try npx in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.