NPX(1)
π NPX(1) π
okay bestie, welcome to the NPX(1) page β section 1 of the manual, the one and only, and yes we are doing this together. grab a strawberry π, we're learning.
β¨ NAME β¨
npx β run a command from a local or remote npm package. that's it, that's the whole vibe. π«Ά
πΈ Synopsis πΈ
npx -- <pkg>[@<version>] [args...]
npx --package=<pkg>[@<version>] -- <cmd> [args...]
npx -c '<cmd> [args...]'
npx --package=foo -c '<cmd> [args...]'
π¦ Description π¦
so basically? this command lets you run an arbitrary command from an npm package β could be one that's already installed locally, could be one you're fetching remotely, either way β and it runs in a context that's a lot like running it via npm run. same energy, different door. π
whatever packages you name with the --package option get dropped into the PATH of the executed command, alongside any locally installed package executables. and the way that --package can be specified multiple times?? iconic. you stack them up and the supplied command runs in an environment where all of those specified packages are available. no cap.
if any of the packages you asked for aren't already sitting in the local project dependencies, then they get installed to a folder in the npm cache, and that folder gets added to the PATH environment variable in the executed process. and before any of that β a prompt is printed. you can suppress that prompt by providing either --yes or --no. your call, bestie. π
package names given without a specifier get matched against whatever version exists in the local project. package names with a specifier only count as a match if they have the exact same name and version as the local dependency. exact. character for character. we don't do approximations here. β¨
if no -c or --call option is provided, then the positional arguments get used to generate the command string. and if no --package options are provided, npm will attempt to determine the executable name from the package specifier given as the first positional argument β using this heuristic, right here:
- 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. π
to run a binary that is not the named binary, specify one or more --package options β which stops npm from inferring the package from the first command argument. periodt.
π npx vs npm exec π
when you run it via the npx binary, all flags and options have to be set prior to any positional arguments. that's the rule. when you run it via npm exec, you can use a double-hyphen -- flag to suppress npm's parsing of switches and options that should be sent to the executed command instead.
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
since the --package option comes after the positional arguments, it is treated as an argument to the executed command. sneaky little thing. π§
in contrast, because of npm's argument parsing logic, running this command is different:
$ npm exec foo@latest bar --package=@npmcli/foo
in this case, npm parses the --package option first, resolving the @npmcli/foo package. then it executes 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 be equivalent to the npx command above:
$ npm exec -- foo@latest bar --package=@npmcli/foo
see how that works?? lowkey beautiful. π
π 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"'
π Compatibility with Older npx Versions π
okay so history lesson, stay with me. the npx binary was rewritten in npm v7.0.0, and the standalone npx package was deprecated at that time. 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. - the
--no-installoption is deprecated, and will be converted to--no. - shell fallback functionality is removed, as it is not advisable.
- the
-pargument is a shorthand for--parseablein npm, but shorthand for--packageinnpx. this is maintained, but only for thenpxexecutable. iykyk. π - 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_OPTIONS(https://nodejs.org/api/cli.html#node_optionsoptions) instead: 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.
β See Also β
npm help run-scriptnpm help scriptsnpm help testnpm help startnpm help restartnpm help stopnpm help confignpm help exec
and that's the whole page bestie, you ate that. π«Άβ¨ this was NPM@10.9.8, from March 2026 β go run something cute, mwah π π
π¦ where this page comes from
- fedora 44: nodejs22-npm 1:10.9.8-1.22.23.1.2.fc44 Β· 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 on : a language model's rewrite of the original, under its terms