npx
npx is a package runner that ships with npm and runs the command-line program inside an npm package. It uses the copy installed in the current project, or downloads the package from the npm registry into a cache first, so a one-off command doesn’t need a global install. Here’s how npx decides what to run:
Since npm 7, npx is a shortcut for the npm exec command, and the standalone npx package from earlier releases is deprecated. Other package managers ship their own runners, such as pnpm dlx in pnpm and bunx in Bun.
Installation and Setup
The Node.js installer includes npm, and npm includes npx, so there’s nothing extra to install. The version matches the npm release that ships with Node.js 26:
$ npx --version
11.20.0
Key Features
- Runs commands from a project’s own dependencies without typing a path into
node_modules. - Downloads packages the project doesn’t have into the npm cache, without changing
package.json. - Asks for confirmation before it installs a package that isn’t in the project.
- Runs an exact release when the package name includes a version, such as
[email protected]. - Runs a command whose name differs from its package’s name with the
--packageoption.
Usage
When a project has Prettier installed as a dev dependency, npx prettier runs the project’s local copy. This command formats the cart.js file:
$ npx prettier --write cart.js
cart.js 52ms
For a package the project doesn’t depend on, npx lists what it needs to download and waits for an answer:
$ npx cowsay "Hello, npx!"
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
_____________
< Hello, npx! >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Options for npx itself go before the package name, because everything after the name goes to the package’s command. The --yes flag skips the prompt, which suits scripts that run without a person at the keyboard:
$ npx --yes create-vite@latest my-app --template vanilla
The typescript package provides the tsc command, so --package names the package and the command follows it:
$ npx --package=typescript tsc --version
Version 7.0.2
For every option and the full lookup rules, see the npx documentation.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 6, 2026