NPX(1)
π npx(1) β the manual page, but make it cute
okay bestie, welcome to npx(1) β the section-1 manual page for npx, and honestly? she's iconic. let's get into it π
β¨ NAME β¨
npx β run a command from a local or remote npm package π¦
πΈ 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 literally any arbitrary command from an npm package β could be one installed locally, could be one fetched remotely β and it runs in a context similar to running it via npm run. lowkey genius.
run this command to execute a package's binary. the important part: any options and arguments after the package name are passed directly to the executed command, not to npx itself. for example, npx create-react-app my-app --template typescript will pass my-app and --template typescript to the create-react-app command. so if you wanna know what options a specific package accepts, go consult that package's own documentation (like, at npmjs.com or in its repository) β npx is not the one gatekeeping that info π
whatever packages you specify with the --package option get provided in the PATH of the executed command, along with any locally installed package executables. and yes, the --package option may be specified multiple times, so you can run the supplied command in an environment where all those specified packages are available. stacking them like π«Ά
if any requested packages aren't present in the local project dependencies, they get installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process. a prompt gets printed (you can suppress it by providing either --yes or --no). so no surprises, she asks first π
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 match only, no vibes-based matching.
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 this 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. easy. - if the package has multiple
binentries, and one of them matches the unscoped portion of thenamefield, then that command will be used. match made β¨ - 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. π that's the vibe check failing, sorry.
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. periodt.
π¦ npx vs npm exec π¦
when run via the npx binary, all flags and options must be set prior to any positional arguments. 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. subtle but she matters.
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's treated as an argument to the executed command. iykyk.
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 will 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. the following command would thus be equivalent to the npx command above:
$ npm exec -- foo@latest bar --package=@npmcli/foo
π 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 π
quick lore drop π: the npx binary was rewritten in npm v7.0.0, and the standalone npx package 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. slay.
- to prevent security and user-experience problems from mistyping package names,
npxprompts before installing anything. suppress this prompt with the-yor--yesoption. (typing is hard, we get it π) - 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--packagein npx. this is maintained, but only for thenpxexecutable. chaotic? yes. still true? also yes. - 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 β here's where to look:https://nodejs.org/api/cli.html#node_optionsoptionsβ 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. π«Ά
fr fr, if you're copy-pasting ancient scripts from 2019 and something explodes? this list is probably why. check it before you spiral π
π 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 version of the npx(1) page ships with NPM@12.2.1, dated October 2026 β so like, future-era documentation, main character energy only π go run something iconic β
π¦ where this page comes from
- arch rolling: npm 12.2.1-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms