npx (Package Runner)
How to execute CLI tools without polluting your system with global installs.
What is npx?
Modern npx is the npm package runner built on npm exec. It provides a way to invoke package executables without requiring a separate global installation. Executed package code still needs to be trusted.
A local CLI can also be invoked through an npm script. npx provides a convenient command-line path to an available local package or an explicitly requested package version.
The Power of Temporary Execution
The true power of npx is how it handles packages that are not installed on your machine.
For a package not available locally, npm exec can fetch it into an npm cache directory and add its executables to the command's PATH. Cached files may remain for reuse; execution does not imply automatic cache deletion.
Choose a package name and version deliberately. An unversioned request can reuse a matching local package; @latest requests a registry tag, while an explicit version requests that version.
The Execution Priority
Current npx uses npm exec package selection rather than the historical global-PATH-first algorithm.
1. Matching local packages can supply their installed executables. A specified version must match the local package to be reused as that request.
2. Missing requested packages can be placed in the npm cache. Interactive prompting and flags such as --yes or --no control consent to that fetch, not a security review.
3. npm runs the selected command with the relevant local/cache executable paths available. The command may still inherit other PATH entries; this is not a package sandbox.
npx Execution Simulator
Follow a local execution simulation that checks an available tool or fetches a requested package into cache. Its final cleanup step represents the command finishing, not a promise that npm deletes cached files.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
npxexecutes Node command-line tools.- It prioritizes locally installed packages (
node_modules/.bin). - Missing requested packages can be fetched into a reusable npm cache; they are not guaranteed to be deleted after execution.
- It eliminates the need for global installations of scaffolding tools (like
create-vite).
Done with this concept?
Mark it complete to track your progress. No login needed.