codekingpro/portable-devtools
114k
1.TH "NPX" "1" "April 2026" "NPM@11.13.0" ""
2.SH "NAME"
3\fBnpx\fR - Run a command from a local or remote npm package
4.SS "Synopsis"
5.P
6.RS 2
7.nf
8npx -- <pkg>\[lB]@<version>\[rB] \[lB]args...\[rB]
9npx --package=<pkg>\[lB]@<version>\[rB] -- <cmd> \[lB]args...\[rB]
10npx -c '<cmd> \[lB]args...\[rB]'
11npx --package=foo -c '<cmd> \[lB]args...\[rB]'
12.fi
13.RE
14.SS "Description"
15.P
16This command allows you to run an arbitrary command from an npm package (either one installed locally, or fetched remotely), in a similar context as running it via \fBnpm run\fR.
17.P
18Run this command to execute a package's binary. Any options and arguments after the package name are passed directly to the executed command, not to npx itself. For example, \fBnpx create-react-app my-app --template typescript\fR will pass \fBmy-app\fR and \fB--template typescript\fR to the \fBcreate-react-app\fR command. To see what options a specific package accepts, consult that package's documentation (e.g., at npmjs.com or in its repository).
19.P
20Whatever packages are specified by the \fB--package\fR option will be provided in the \fBPATH\fR of the executed command, along with any locally installed package executables. The \fB--package\fR option may be specified multiple times, to execute the supplied command in an environment where all specified packages are available.
21.P
22If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the \fBPATH\fR environment variable in the executed process. A prompt is printed (which can be suppressed by providing either \fB--yes\fR or \fB--no\fR).
23.P
24Package 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.
25.P
26If no \fB-c\fR or \fB--call\fR option is provided, then the positional arguments are used to generate the command string. If no \fB--package\fR 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:
27.RS 0
28.IP \(bu 4
29If the package has a single entry in its \fBbin\fR field in \fBpackage.json\fR, or if all entries are aliases of the same command, then that command will be used.
30.IP \(bu 4
31If the package has multiple \fBbin\fR entries, and one of them matches the unscoped portion of the \fBname\fR field, then that command will be used.
32.IP \(bu 4
33If this does not result in exactly one option (either because there are no bin entries, or none of them match the \fBname\fR of the package), then \fBnpm exec\fR exits with an error.
34.RE 0
35
36.P
37To run a binary \fIother than\fR the named binary, specify one or more \fB--package\fR options, which will prevent npm from inferring the package from the first command argument.
38.SS "\fBnpx\fR vs \fBnpm exec\fR"
39.P
40When run via the \fBnpx\fR binary, all flags and options \fImust\fR be set prior to any positional arguments. When run via \fBnpm exec\fR, a double-hyphen \fB--\fR flag can be used to suppress npm's parsing of switches and options that should be sent to the executed command.
41.P
42For example:
43.P
44.RS 2
45.nf
46$ npx foo@latest bar --package=@npmcli/foo
47.fi
48.RE
49.P
50In this case, npm will resolve the \fBfoo\fR package name, and run the following command:
51.P
52.RS 2
53.nf
54$ foo bar --package=@npmcli/foo
55.fi
56.RE
57.P
58Since the \fB--package\fR option comes \fIafter\fR the positional arguments, it is treated as an argument to the executed command.
59.P
60In contrast, due to npm's argument parsing logic, running this command is different:
61.P
62.RS 2
63.nf
64$ npm exec foo@latest bar --package=@npmcli/foo
65.fi
66.RE
67.P
68In this case, npm will parse the \fB--package\fR option first, resolving the \fB@npmcli/foo\fR package. Then, it will execute the following command in that context:
69.P
70.RS 2
71.nf
72$ foo@latest bar
73.fi
74.RE
75.P
76The 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 \fBnpx\fR command above:
77.P
78.RS 2
79.nf
80$ npm exec -- foo@latest bar --package=@npmcli/foo
81.fi
82.RE
83.SS "Examples"
84.P
85Run the version of \fBtap\fR in the local dependencies, with the provided arguments:
86.P
87.RS 2
88.nf
89$ npm exec -- tap --bail test/foo.js
90$ npx tap --bail test/foo.js
91.fi
92.RE
93.P
94Run a command \fIother than\fR the command whose name matches the package name by specifying a \fB--package\fR option:
95.P
96.RS 2
97.nf
98$ npm exec --package=foo -- bar --bar-argument
99# ~ or ~
100$ npx --package=foo bar --bar-argument
101.fi
102.RE
103.P
104Run an arbitrary shell script, in the context of the current project:
105.P
106.RS 2
107.nf
108$ npm x -c 'eslint && say "hooray, lint passed"'
109$ npx -c 'eslint && say "hooray, lint passed"'
110.fi
111.RE
112.SS "Compatibility with Older npx Versions"
113.P
114The \fBnpx\fR binary was rewritten in npm v7.0.0, and the standalone \fBnpx\fR package deprecated at that time. \fBnpx\fR uses the \fBnpm exec\fR 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.
115.P
116This resulted in some shifts in its functionality:
117.RS 0
118.IP \(bu 4
119Any \fBnpm\fR config value may be provided.
120.IP \(bu 4
121To prevent security and user-experience problems from mistyping package names, \fBnpx\fR prompts before installing anything. Suppress this prompt with the \fB-y\fR or \fB--yes\fR option.
122.IP \(bu 4
123The \fB--no-install\fR option is deprecated, and will be converted to \fB--no\fR.
124.IP \(bu 4
125Shell fallback functionality is removed, as it is not advisable.
126.IP \(bu 4
127The \fB-p\fR argument is a shorthand for \fB--parseable\fR in npm, but shorthand for \fB--package\fR in npx. This is maintained, but only for the \fBnpx\fR executable.
128.IP \(bu 4
129The \fB--ignore-existing\fR option is removed. Locally installed bins are always present in the executed process \fBPATH\fR.
130.IP \(bu 4
131The \fB--npm\fR option is removed. \fBnpx\fR will always use the \fBnpm\fR it ships with.
132.IP \(bu 4
133The \fB--node-arg\fR and \fB-n\fR options have been removed. Use \fB\[rs]fBNODE_OPTIONS\[rs]fR\fR \fI\(lahttps://nodejs.org/api/cli.html#node_optionsoptions\(ra\fR instead: e.g., \fBNODE_OPTIONS="--trace-warnings --trace-exit" npx foo --random=true\fR
134.IP \(bu 4
135The \fB--always-spawn\fR option is redundant, and thus removed.
136.IP \(bu 4
137The \fB--shell\fR option is replaced with \fB--script-shell\fR, but maintained in the \fBnpx\fR executable for backwards compatibility.
138.RE 0
139
140.SS "See Also"
141.RS 0
142.IP \(bu 4
143npm help run
144.IP \(bu 4
145npm help scripts
146.IP \(bu 4
147npm help test
148.IP \(bu 4
149npm help start
150.IP \(bu 4
151npm help restart
152.IP \(bu 4
153npm help stop
154.IP \(bu 4
155npm help config
156.IP \(bu 4
157npm help exec
158.RE 0
159 