Skip to content
FLAVIO COPES
flaviocopes.com
2026

The npx Node Package Runner

By

Learn how npx runs commands from local or remote npm packages, how it relates to npm exec, and how to run a specific package version safely.

~~~

npx runs a command from an npm package. It uses a locally installed package when available, or can fetch a package temporarily when it is missing.

npx ships with modern versions of npm. The old standalone npx package is deprecated.

Run a local command

Suppose ESLint is installed in your project:

npm install --save-dev eslint

You can run its executable without knowing its path inside node_modules:

npx eslint .

This is the main reason to use npx: project tools stay local, and every project can use its own version.

Inside a package.json script you normally do not need npx. npm already adds local package executables to the script’s PATH.

Run a package without adding it to the project

You can also run a command that is not installed locally:

npx cowsay "Hello"

npx tells you that it needs to install the missing package and asks for confirmation. Pass --yes only when you have already checked the package name and trust the code:

npx --yes cowsay "Hello"

The package is fetched into npm’s cache for the command. It is not added to your project’s dependencies.

Be careful with typos. Running an unfamiliar package means running code downloaded from the registry on your computer.

Run a specific version

Add a version after the package name:

npx [email protected] "Hello"

This is useful when documentation or a project requires a particular release.

npx and npm exec

Modern npx is based on npm exec. These commands are equivalent for many common cases:

npx eslint .
npm exec -- eslint .

There is one syntax detail worth remembering: options before the package name belong to npx; options after it are passed to the command being run.

The official npx documentation lists the differences between npx and npm exec, including compatibility changes made when npx was rewritten in npm 7.

Tagged: Node.js · All topics
~~~

Related posts about node: