NPX(1)

πŸ“¦ version 24.18.1, in opensuse-leap 16.0

πŸ’– NPX(1) β€” the npx girlies' manual πŸ’–

okay bestie, welcome to the npx page, manual section 1. pull up a chair, grab a strawberry πŸ“, and let's get into it. no cap, this one's iconic.


✨ NAME ✨

npx β€” run a command from a local or remote npm package. yeah. that's the whole vibe. run a thing, from a package, local or remote. πŸ’…


✨ Synopsis ✨

npx -- <pkg>[@<version>] [args...]
npx --package=<pkg>[@<version>] -- <cmd> [args...]
npx -c '<cmd> [args...]'
npx --package=foo -c '<cmd> [args...]'

look at those four lil lines. four whole ways to pop off. 🌸


✨ Description ✨

so basically: this command lets you run an arbitrary command from an npm package β€” and that package can either be one installed locally or one fetched remotely. the context it runs in is similar to running it via npm run. 🫢

run this command to execute a package's binary. any options and arguments after the package name get 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 documentation (like at npmjs.com or in its repository). npx is not the one holding that lore, iykyk. 😭

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 bestie β€” the --package option may be specified multiple times, so you can execute the supplied command in an environment where all specified packages are available. stacking packages like it's a fit check. πŸ‘‘

if any requested packages are not present in the local project dependencies, then they get installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process. and a prompt is printed β€” which you can suppress by providing either --yes or --no. it's giving "consent first, bestie." πŸŽ€

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. name. and. version. no wiggle room, 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 the following heuristic:

  • if the package has a single entry in its bin field in package.json, or if all entries are aliases of the same command, then that command will be used.
  • if the package has multiple bin entries, and one of them matches the unscoped portion of the name field, then that command will be used.
  • if this does not result in exactly one option (either because there are no bin entries, or none of them match the name of the package), then npm exec exits with an error. πŸ’€ not the ambiguous-bin situation.

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.


✨ npx vs npm exec ✨

okay so when you run via the npx binary, all flags and options must be set prior to any positional arguments. periodt. when you 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

since the --package option comes after the positional arguments, it is treated as an argument to the executed command. sneaky little guy. πŸ™ˆ

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

see how that works? -- is the "okay we're done talking to npm, talk to the command now" line. icon behavior. ⭐


✨ 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 second one is my favorite fr fr, say "hooray, lint passed" is literally me every time CI goes green. πŸ˜­πŸ’–


✨ Compatibility with Older npx Versions ✨

lore time, bestie. πŸ“– 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, npx prompts before installing anything. suppress this prompt with the -y or --yes option.
  • the --no-install option is deprecated, and will be converted to --no.
  • shell fallback functionality is removed, as it is not advisable.
  • the -p argument is a shorthand for --parseable in npm, but shorthand for --package in npx. this is maintained, but only for the npx executable. (chaos, honestly, but it's kept. πŸ’€)
  • the --ignore-existing option is removed. locally installed bins are always present in the executed process PATH.
  • the --npm option is removed. npx will always use the npm it ships with.
  • the --node-arg and -n options have been removed. use NODE_OPTIONS ⟨https://nodejs.org/api/cli.html#node_optionsoptions⟩ instead: e.g., NODE_OPTIONS="--trace-warnings --trace-exit" npx foo --random=true
  • the --always-spawn option is redundant, and thus removed.
  • the --shell option is replaced with --script-shell, but maintained in the npx executable for backwards compatibility.
so like... a lot of old flags just do not exist anymore, bestie. if a tutorial from 2019 tells you to use --npm or -n, it's over. use NODE_OPTIONS instead. 🫢

✨ See Also ✨

  • npm help run
  • npm help scripts
  • npm help test
  • npm help start
  • npm help restart
  • npm help stop
  • npm help config
  • npm help exec

and that's the whole page, bestie. πŸ¦‹ you just ate this documentation up, no crumbs. this was npx from NPM@11.16.0, dated May 2026. mwah. πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from