Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
npm-exec.1351 linesDownload Raw Back to man1
1.TH "NPM-EXEC" "1" "April 2026" "NPM@11.13.0" ""
2.SH "NAME"
3\fBnpm-exec\fR - Run a command from a local or remote npm package
4.SS "Synopsis"
5.P
6.RS 2
7.nf
8npm exec -- <pkg>\[lB]@<version>\[rB] \[lB]args...\[rB]
9npm exec --package=<pkg>\[lB]@<version>\[rB] -- <cmd> \[lB]args...\[rB]
10npm exec -c '<cmd> \[lB]args...\[rB]'
11npm exec --package=foo -c '<cmd> \[lB]args...\[rB]'
12
13alias: x
14.fi
15.RE
16.SS "Description"
17.P
18This 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.
19.P
20Run without positional arguments or \fB--call\fR, this allows you to interactively run commands in the same sort of shell environment that \fBpackage.json\fR scripts are run. Interactive mode is not supported in CI environments when standard input is a TTY, to prevent hangs.
21.P
22Whatever 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.
23.P
24If any requested packages are not present in the local project dependencies, then a prompt is printed, which can be suppressed by providing either \fB--yes\fR or \fB--no\fR. When standard input is not a TTY or a CI environment is detected, \fB--yes\fR is assumed. The requested packages are installed to a folder in the npm cache, which is added to the \fBPATH\fR environment variable in the executed process.
25.P
26Package 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.
27.P
28If 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:
29.RS 0
30.IP \(bu 4
31If 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.
32.IP \(bu 4
33If 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.
34.IP \(bu 4
35If 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.
36.RE 0
37
38.P
39To 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.
40.SS "\fBnpx\fR vs \fBnpm exec\fR"
41.P
42When 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.
43.P
44For example:
45.P
46.RS 2
47.nf
48$ npx foo@latest bar --package=@npmcli/foo
49.fi
50.RE
51.P
52In this case, npm will resolve the \fBfoo\fR package name, and run the following command:
53.P
54.RS 2
55.nf
56$ foo bar --package=@npmcli/foo
57.fi
58.RE
59.P
60Since the \fB--package\fR option comes \fIafter\fR the positional arguments, it is treated as an argument to the executed command.
61.P
62In contrast, due to npm's argument parsing logic, running this command is different:
63.P
64.RS 2
65.nf
66$ npm exec foo@latest bar --package=@npmcli/foo
67.fi
68.RE
69.P
70In 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:
71.P
72.RS 2
73.nf
74$ foo@latest bar
75.fi
76.RE
77.P
78The 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:
79.P
80.RS 2
81.nf
82$ npm exec -- foo@latest bar --package=@npmcli/foo
83.fi
84.RE
85.SS "Configuration"
86.SS "\fBpackage\fR"
87.RS 0
88.IP \(bu 4
89Default:
90.IP \(bu 4
91Type: String (can be set multiple times)
92.RE 0
93
94.P
95The package or packages to install for npm help exec
96.SS "\fBcall\fR"
97.RS 0
98.IP \(bu 4
99Default: ""
100.IP \(bu 4
101Type: String
102.RE 0
103
104.P
105Optional companion option for \fBnpm exec\fR, \fBnpx\fR that allows for specifying a custom command to be run along with the installed packages.
106.P
107.RS 2
108.nf
109npm exec --package yo --package generator-node --call "yo node"
110.fi
111.RE
112.SS "\fBworkspace\fR"
113.RS 0
114.IP \(bu 4
115Default:
116.IP \(bu 4
117Type: String (can be set multiple times)
118.RE 0
119
120.P
121Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
122.P
123Valid values for the \fBworkspace\fR config are either:
124.RS 0
125.IP \(bu 4
126Workspace names
127.IP \(bu 4
128Path to a workspace directory
129.IP \(bu 4
130Path to a parent workspace directory (will result in selecting all workspaces within that folder)
131.RE 0
132
133.P
134When set for the \fBnpm init\fR command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
135.P
136This value is not exported to the environment for child processes.
137.SS "\fBworkspaces\fR"
138.RS 0
139.IP \(bu 4
140Default: null
141.IP \(bu 4
142Type: null or Boolean
143.RE 0
144
145.P
146Set to true to run the command in the context of \fBall\fR configured workspaces.
147.P
148Explicitly setting this to false will cause commands like \fBinstall\fR to ignore workspaces altogether. When not set explicitly:
149.RS 0
150.IP \(bu 4
151Commands that operate on the \fBnode_modules\fR tree (install, update, etc.) will link workspaces into the \fBnode_modules\fR folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, \fIunless\fR one or more workspaces are specified in the \fBworkspace\fR config.
152.RE 0
153
154.P
155This value is not exported to the environment for child processes.
156.SS "\fBinclude-workspace-root\fR"
157.RS 0
158.IP \(bu 4
159Default: false
160.IP \(bu 4
161Type: Boolean
162.RE 0
163
164.P
165Include the workspace root when workspaces are enabled for a command.
166.P
167When false, specifying individual workspaces via the \fBworkspace\fR config, or all workspaces via the \fBworkspaces\fR flag, will cause npm to operate only on the specified workspaces, and not on the root project.
168.P
169This value is not exported to the environment for child processes.
170.SS "Examples"
171.P
172Run the version of \fBtap\fR in the local dependencies, with the provided arguments:
173.P
174.RS 2
175.nf
176$ npm exec -- tap --bail test/foo.js
177$ npx tap --bail test/foo.js
178.fi
179.RE
180.P
181Run a command \fIother than\fR the command whose name matches the package name by specifying a \fB--package\fR option:
182.P
183.RS 2
184.nf
185$ npm exec --package=foo -- bar --bar-argument
186# ~ or ~
187$ npx --package=foo bar --bar-argument
188.fi
189.RE
190.P
191Run an arbitrary shell script, in the context of the current project:
192.P
193.RS 2
194.nf
195$ npm x -c 'eslint && say "hooray, lint passed"'
196$ npx -c 'eslint && say "hooray, lint passed"'
197.fi
198.RE
199.SS "Workspaces support"
200.P
201You may use the \fB\[rs]fBworkspace\[rs]fR\fR \fI\(la/using-npm/config#workspace\(ra\fR or \fB\[rs]fBworkspaces\[rs]fR\fR \fI\(la/using-npm/config#workspaces\(ra\fR configs in order to run an arbitrary command from an npm package (either one installed locally, or fetched remotely) in the context of the specified workspaces. If no positional argument or \fB--call\fR option is provided, it will open an interactive subshell in the context of each of these configured workspaces one at a time.
202.P
203Given a project with configured workspaces, e.g:
204.P
205.RS 2
206.nf
207.
208+-- package.json
209`-- packages
210   +-- a
211   |   `-- package.json
212   +-- b
213   |   `-- package.json
214   `-- c
215       `-- package.json
216.fi
217.RE
218.P
219Assuming the workspace configuration is properly set up at the root level \fBpackage.json\fR file. e.g:
220.P
221.RS 2
222.nf
223{
224    "workspaces": \[lB] "./packages/*" \[rB]
225}
226.fi
227.RE
228.P
229You can execute an arbitrary command from a package in the context of each of the configured workspaces when using the \fB\[rs]fBworkspaces\[rs]fR config options\fR \fI\(la/using-npm/config#workspace\(ra\fR, in this example we're using \fBeslint\fR to lint any js file found within each workspace folder:
230.P
231.RS 2
232.nf
233npm exec --ws -- eslint ./*.js
234.fi
235.RE
236.SS "Filtering workspaces"
237.P
238It's also possible to execute a command in a single workspace using the \fBworkspace\fR config along with a name or directory path:
239.P
240.RS 2
241.nf
242npm exec --workspace=a -- eslint ./*.js
243.fi
244.RE
245.P
246The \fBworkspace\fR config can also be specified multiple times in order to run a specific script in the context of multiple workspaces. When defining values for the \fBworkspace\fR config in the command line, it also possible to use \fB-w\fR as a shorthand, e.g:
247.P
248.RS 2
249.nf
250npm exec -w a -w b -- eslint ./*.js
251.fi
252.RE
253.P
254This last command will run the \fBeslint\fR command in both \fB./packages/a\fR and \fB./packages/b\fR folders.
255.SS "Compatibility with Older npx Versions"
256.P
257The \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.
258.P
259This resulted in some shifts in its functionality:
260.RS 0
261.IP \(bu 4
262Any \fBnpm\fR config value may be provided.
263.IP \(bu 4
264To 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.
265.IP \(bu 4
266The \fB--no-install\fR option is deprecated, and will be converted to \fB--no\fR.
267.IP \(bu 4
268Shell fallback functionality is removed, as it is not advisable.
269.IP \(bu 4
270The \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.
271.IP \(bu 4
272The \fB--ignore-existing\fR option is removed. Locally installed bins are always present in the executed process \fBPATH\fR.
273.IP \(bu 4
274The \fB--npm\fR option is removed. \fBnpx\fR will always use the \fBnpm\fR it ships with.
275.IP \(bu 4
276The \fB--node-arg\fR and \fB-n\fR options are removed.
277.IP \(bu 4
278The \fB--always-spawn\fR option is redundant, and thus removed.
279.IP \(bu 4
280The \fB--shell\fR option is replaced with \fB--script-shell\fR, but maintained in the \fBnpx\fR executable for backwards compatibility.
281.RE 0
282
283.SS "A note on caching"
284.P
285The npm cli utilizes its internal package cache when using the package name specified. You can use the following to change how and when the cli uses this cache. See npm help cache for more on how the cache works.
286.SS "prefer-online"
287.P
288Forces staleness checks for packages, making the cli look for updates immediately even if the package is already in the cache.
289.SS "prefer-offline"
290.P
291Bypasses staleness checks for packages. Missing data will still be requested from the server. To force full offline mode, use \fBoffline\fR.
292.SS "offline"
293.P
294Forces full offline mode. Any packages not locally cached will result in an error.
295.SS "workspace"
296.RS 0
297.IP \(bu 4
298Default:
299.IP \(bu 4
300Type: String (can be set multiple times)
301.RE 0
302
303.P
304Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
305.P
306Valid values for the \fBworkspace\fR config are either:
307.RS 0
308.IP \(bu 4
309Workspace names
310.IP \(bu 4
311Path to a workspace directory
312.IP \(bu 4
313Path to a parent workspace directory (will result to selecting all of the nested workspaces)
314.RE 0
315
316.P
317This value is not exported to the environment for child processes.
318.SS "workspaces"
319.RS 0
320.IP \(bu 4
321Alias: \fB--ws\fR
322.IP \(bu 4
323Type: Boolean
324.IP \(bu 4
325Default: \fBfalse\fR
326.RE 0
327
328.P
329Run scripts in the context of all configured workspaces for the current project.
330.SS "See Also"
331.RS 0
332.IP \(bu 4
333npm help run
334.IP \(bu 4
335npm help scripts
336.IP \(bu 4
337npm help test
338.IP \(bu 4
339npm help start
340.IP \(bu 4
341npm help restart
342.IP \(bu 4
343npm help stop
344.IP \(bu 4
345npm help config
346.IP \(bu 4
347npm help workspaces
348.IP \(bu 4
349npm help npx
350.RE 0
351 
codekingpro/portable-devtools · Team Ai