NPX(1)
π
NPX(1) β the girlies' guide to npx
Okay so bestie, pull up a chair, because we're talking about npx β the icon, the moment, the "run a command from a local or remote npm package" queen. This is npx(1), and she's got range. Let's go. π
β¨ NAME
npx β run a command from a local or remote npm package. Periodt. π
πΈ Synopsis
Lowkey the whole vibe in four lines:
npx -- <pkg>[@<version>] [args...]
npx --package=<pkg>[@<version>] -- <cmd> [args...]
npx -c '<cmd> [args...]'
npx --package=foo -c '<cmd> [args...]'
π¦ Description
So here's the tea β: this command lets you run an arbitrary command from an npm package β either one already installed locally, or one fetched remotely β in basically the same context as running it via npm run. Same energy, different door.
Run this command to execute a package's binary. And this is the important part, so listen up π: any options and arguments after the package name are passed directly to the executed command, not to npx itself. Like, they go to the other command. Not to us. We're just the messenger.
For example, npx create-react-app my-app --template typescript will pass my-app and --template typescript to the create-react-app command. Not to npx. To create-react-app. (Not me having to learn this the hard way π.) So if you wanna know what options a specific package accepts β consult that package's documentation, bestie. Like, at npmjs.com or in its repository. We can't speak for her.
Whatever packages are specified by the --package option will be provided in the PATH of the executed command, along with any locally installed package executables. And here's the slay part: --package may be specified multiple times, so you can execute the supplied command in an environment where all the specified packages are available. A whole little squad in your PATH. π«Ά
If any requested packages are not present in the local project dependencies, then they're installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process. And because npm is a responsible queen, a prompt is printed β which can be suppressed by providing either --yes or --no. (Vibe check before install, iykyk.)
Package names provided without a specifier will be matched with whatever version exists in the local project. Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency. Exact. Same. No approximations. π
If no -c or --call option is provided, then the positional arguments are used to generate the command string. And if no --package options are provided, then npm will attempt to determine the executable name from the package specifier provided as the first positional argument, according to the following heuristic:
- If the package has a single entry in its
binfield inpackage.json, or if all entries are aliases of the same command, then that command will be used. β¨ - If the package has multiple
binentries, and one of them matches the unscoped portion of thenamefield, then that command will be used. - If this does not result in exactly one option (either because there are no
binentries, or none of them match the name of the package), thennpm execexits with an error. π¨ Not the vibe, but it's the rule.
To run a binary other than the named binary, specify one or more --package options β which will prevent npm from inferring the package from the first command argument. Main character move: just say what you want. π
π§ npx vs npm exec
Okay this one's important, so put your phone down for a sec π.
When run via the npx binary, all flags and options must be set prior to any positional arguments. Like, before. Up front. No stragglers.
When run via npm exec, a double-hyphen -- flag can be used to suppress npm's parsing of switches and options that should be sent to the executed command.
For example:
$ npx foo@latest bar --package=@npmcli/foo
In this case, npm will resolve the foo package name, and run the following command:
$ foo bar --package=@npmcli/foo
Because the --package option comes after the positional arguments, it is treated as an argument to the executed command. It's a passenger, not a pilot. π₯οΈ
In contrast, due to npm's argument parsing logic, running this command is different:
$ npm exec foo@latest bar --package=@npmcli/foo
In this case, npm will parse the --package option first, resolving the @npmcli/foo package. Then it'll execute the following command in that context:
$ foo@latest bar
The double-hyphen character is recommended to explicitly tell npm to stop parsing command line options and switches. So the following command would thus be equivalent to the npx command above:
$ npm exec -- foo@latest bar --package=@npmcli/foo
See? -- is the boundary. The velvet rope. The "we're done with options, now it's the command's turn" line. π
β Examples
Run the version of tap in the local dependencies, with the provided arguments:
$ npm exec -- tap --bail test/foo.js
$ npx tap --bail test/foo.js
Run a command other than the command whose name matches the package name by specifying a --package option:
$ npm exec --package=foo -- bar --bar-argument
# ~ or ~
$ npx --package=foo bar --bar-argument
Run an arbitrary shell script, in the context of the current project:
$ npm x -c 'eslint && say "hooray, lint passed"'
$ npx -c 'eslint && say "hooray, lint passed"'
That last one? Literally the most satisfying thing you will ever type. hooray, lint passed π₯Ήβ¨
π Compatibility with Older npx Versions
Storytime, bestie π. The npx binary was rewritten in npm v7.0.0, and the standalone npx package was deprecated at that time. So old npx is not the npx you know today β she's evolved.
npx uses the npm exec command instead of a separate argument parser and install process, with some affordances to maintain backwards compatibility with the arguments it accepted in previous versions.
This resulted in some shifts in its functionality:
- Any npm config value may be provided.
- To prevent security and user-experience problems from mistyping package names,
npxprompts before installing anything. Suppress this prompt with the-yor--yesoption. (Yes queen, safety first. π‘οΈ) - The
--no-installoption is deprecated, and will be converted to--no. Heads up! - Shell fallback functionality is removed, as it is not advisable. Gone. Not coming back. π ββοΈ
- The
-pargument is a shorthand for--parseablein npm, but shorthand for--packageinnpx. This is maintained, but only for thenpxexecutable. Sneaky little context-dependent icon. π - The
--ignore-existingoption is removed. Locally installed bins are always present in the executed processPATH. - The
--npmoption is removed.npxwill always use the npm it ships with. - The
--node-argand-noptions have been removed. UseNODE_OPTIONSinstead: e.g.,NODE_OPTIONS="--trace-warnings --trace-exit" npx foo --random=true - The
--always-spawnoption is redundant, and thus removed. - The
--shelloption is replaced with--script-shell, but maintained in thenpxexecutable for backwards compatibility.
Okay but fr fr β if you're copying an ancient Stack Overflow answer from 2016, this list is your bestie. Check it before you rage. π
π See Also
npm help runnpm help scriptsnpm help testnpm help startnpm help restartnpm help stopnpm help confignpm help exec
And that's the whole page, bestie! π«Άβ¨ This absolute baddie of a manpage is from NPM@11.17.0, dated June 2026 β so go forth, pass your args after the package name, and remember: -- is the velvet rope. Obsessed with you. πππ¦
π¦ where this page comes from
- centos-stream 10: nodejs24-npm 1:11.17.0-1.24.19.0.1.el10 Β· Apache-2.0 AND Artistic-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BlueOak-1.0.0 AND CC-BY-3.0 AND CC0-1.0 AND ISC AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms