NPX(1)

πŸ“¦
version 11.17.0 Β· 5 versions
, in centos-stream 10

πŸ’… 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 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 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, npx prompts before installing anything. Suppress this prompt with the -y or --yes option. (Yes queen, safety first. πŸ›‘οΈ)
  • The --no-install option 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 -p argument is a shorthand for --parseable in npm, but shorthand for --package in npx. This is maintained, but only for the npx executable. Sneaky little context-dependent icon. 😏
  • 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 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.
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 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! 🫢✨ 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