pnpx
Execute Node.js packages
TLDR
Execute the binary from a given npm module
Execute a specific binary from a given npm module, in case the module has multiple binaries
Display help
SYNOPSIS
pnpx [options] <package> [arguments]
PARAMETERS
--package <package_name>
Explicitly specify the package to execute. Useful when the package name isn't a valid executable name.
-c, --cache
Force re-downloading dependencies, bypassing the cache.
-d, --debug
Enable debug logging.
-y, --yes
Bypass prompts when installing packages.
-v, --version
Show version number.
--ignore-existing
Ignore any existing globally installed versions of the package.
--no-install
Do not install the package if it is not already present.
--shell <shell_command>
Execute the command in a specific shell. Defaults to the current shell.
--silent
Suppress output to the console.
--package-manager <npm|yarn|pnpm>
Specify the package manager to use for installing the package (default: npm).
DESCRIPTION
pnpx
is a command-line tool designed to execute Node.js packages.
Unlike npm install -g
, pnpx
allows you to run packages without needing to install them globally.
This is particularly useful for executing infrequently used tools, experimenting with different versions of packages, and avoiding global dependency conflicts.
pnpx
will download and cache the package if it's not already present, making subsequent invocations faster. It also attempts to prevent common issues like command shadowing by ensuring the executed package isn't already shadowed by a global installation. pnpx
helps maintain a cleaner global environment and simplifies the process of using and testing Node.js command-line tools. pnpx
is included with npm (Node Package Manager) since version 5.2.0.
CAVEATS
pnpx
requires Node.js and npm to be installed. Network connectivity is required for downloading packages that are not already cached.
EXECUTION CONTEXT
The package is executed in a new Node.js process with the current working directory as the base. This allows packages to access local files and configurations. pnpx
automatically adds the directory containing the executed package's `node_modules/.bin` to the PATH during execution, ensuring that any dependencies of the package are also available as commands.
HISTORY
pnpx
was created to address the common problem of managing global dependencies in Node.js projects. Before pnpx
, developers often had to install packages globally to use their command-line tools, leading to dependency conflicts and a cluttered global environment. pnpx
was introduced as a convenient way to run packages on demand without the need for global installation. pnpx
is included with npm since version 5.2.0.