codekingpro/portable-devtools
114k
1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>npx</title>
4<style>
5body {
6 background-color: #ffffff;
7 color: #24292e;
8
9 margin: 0;
10
11 line-height: 1.5;
12
13 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
14}
15#rainbar {
16 height: 10px;
17 background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
18}
19
20a {
21 text-decoration: none;
22 color: #0366d6;
23}
24a:hover {
25 text-decoration: underline;
26}
27
28pre {
29 margin: 1em 0px;
30 padding: 1em;
31 border: solid 1px #e1e4e8;
32 border-radius: 6px;
33
34 display: block;
35 overflow: auto;
36
37 white-space: pre;
38
39 background-color: #f6f8fa;
40 color: #393a34;
41}
42code {
43 font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
44 font-size: 85%;
45 padding: 0.2em 0.4em;
46 background-color: #f6f8fa;
47 color: #393a34;
48}
49pre > code {
50 padding: 0;
51 background-color: inherit;
52 color: inherit;
53}
54h1, h2, h3 {
55 font-weight: 600;
56}
57
58#logobar {
59 background-color: #333333;
60 margin: 0 auto;
61 padding: 1em 4em;
62}
63#logobar .logo {
64 float: left;
65}
66#logobar .title {
67 font-weight: 600;
68 color: #dddddd;
69 float: left;
70 margin: 5px 0 0 1em;
71}
72#logobar:after {
73 content: "";
74 display: block;
75 clear: both;
76}
77
78#content {
79 margin: 0 auto;
80 padding: 0 4em;
81}
82
83#table_of_contents > h2 {
84 font-size: 1.17em;
85}
86#table_of_contents ul:first-child {
87 border: solid 1px #e1e4e8;
88 border-radius: 6px;
89 padding: 1em;
90 background-color: #f6f8fa;
91 color: #393a34;
92}
93#table_of_contents ul {
94 list-style-type: none;
95 padding-left: 1.5em;
96}
97#table_of_contents li {
98 font-size: 0.9em;
99}
100#table_of_contents li a {
101 color: #000000;
102}
103
104header.title {
105 border-bottom: solid 1px #e1e4e8;
106}
107header.title > h1 {
108 margin-bottom: 0.25em;
109}
110header.title > .description {
111 display: block;
112 margin-bottom: 0.5em;
113 line-height: 1;
114}
115
116header.title .version {
117 font-size: 0.8em;
118 color: #666666;
119}
120
121footer#edit {
122 border-top: solid 1px #e1e4e8;
123 margin: 3em 0 4em 0;
124 padding-top: 2em;
125}
126
127table {
128 width: 100%;
129 margin: 1em 0;
130 border-radius: 6px;
131 border: 1px solid #e1e4e8;
132 overflow: hidden;
133 border-collapse: separate;
134 border-spacing: 0;
135}
136
137table thead {
138 background-color: #f6f8fa;
139}
140
141table tbody {
142 background-color: #ffffff;
143}
144
145table th,
146table td {
147 padding: 0.75em;
148 text-align: left;
149 border-right: 1px solid #e1e4e8;
150 border-bottom: 1px solid #e1e4e8;
151}
152
153table th:last-child,
154table td:last-child {
155 border-right: none;
156}
157
158table tbody tr:last-child td {
159 border-bottom: none;
160}
161
162table th {
163 font-weight: 600;
164 background-color: #f6f8fa;
165}
166
167table code {
168 white-space: nowrap;
169}
170
171</style>
172</head>
173<body>
174<div id="banner">
175<div id="rainbar"></div>
176<div id="logobar">
177<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
178<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
179<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
180</svg>
181<div class="title">
182npm command-line interface
183</div>
184</div>
185</div>
186
187<section id="content">
188<header class="title">
189<h1 id="----npx----11130">
190 <span>npx</span>
191 <span class="version">@11.13.0</span>
192</h1>
193<span class="description">Run a command from a local or remote npm package</span>
194</header>
195
196<section id="table_of_contents">
197<h2 id="table-of-contents">Table of contents</h2>
198<div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#npx-vs-npm-exec"><code>npx</code> vs <code>npm exec</code></a></li><li><a href="#examples">Examples</a></li><li><a href="#compatibility-with-older-npx-versions">Compatibility with Older npx Versions</a></li><li><a href="#see-also">See Also</a></li></ul></div>
199</section>
200
201<div id="_content"><h3 id="synopsis">Synopsis</h3>
202<pre><code class="language-bash">npx -- <pkg>[@<version>] [args...]
203npx --package=<pkg>[@<version>] -- <cmd> [args...]
204npx -c '<cmd> [args...]'
205npx --package=foo -c '<cmd> [args...]'
206</code></pre>
207<h3 id="description">Description</h3>
208<p>This 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 <code>npm run</code>.</p>
209<p>Run 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, <code>npx create-react-app my-app --template typescript</code> will pass <code>my-app</code> and <code>--template typescript</code> to the <code>create-react-app</code> command. To see what options a specific package accepts, consult that package's documentation (e.g., at npmjs.com or in its repository).</p>
210<p>Whatever packages are specified by the <code>--package</code> option will be provided in the <code>PATH</code> of the executed command, along with any locally installed package executables.
211The <code>--package</code> option may be specified multiple times, to execute the supplied command in an environment where all specified packages are available.</p>
212<p>If 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 <code>PATH</code> environment variable in the executed process.
213A prompt is printed (which can be suppressed by providing either <code>--yes</code> or <code>--no</code>).</p>
214<p>Package names provided without a specifier will be matched with whatever version exists in the local project.
215Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency.</p>
216<p>If no <code>-c</code> or <code>--call</code> option is provided, then the positional arguments are used to generate the command string.
217If no <code>--package</code> 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:</p>
218<ul>
219<li>If the package has a single entry in its <code>bin</code> field in <code>package.json</code>, or if all entries are aliases of the same command, then that command will be used.</li>
220<li>If the package has multiple <code>bin</code> entries, and one of them matches the unscoped portion of the <code>name</code> field, then that command will be used.</li>
221<li>If this does not result in exactly one option (either because there are no bin entries, or none of them match the <code>name</code> of the package), then
222<code>npm exec</code> exits with an error.</li>
223</ul>
224<p>To run a binary <em>other than</em> the named binary, specify one or more
225<code>--package</code> options, which will prevent npm from inferring the package from the first command argument.</p>
226<h3 id="npx-vs-npm-exec"><code>npx</code> vs <code>npm exec</code></h3>
227<p>When run via the <code>npx</code> binary, all flags and options <em>must</em> be set prior to any positional arguments.
228When run via <code>npm exec</code>, a double-hyphen <code>--</code> flag can be used to suppress npm's parsing of switches and options that should be sent to the executed command.</p>
229<p>For example:</p>
230<pre><code>$ npx foo@latest bar --package=@npmcli/foo
231</code></pre>
232<p>In this case, npm will resolve the <code>foo</code> package name, and run the following command:</p>
233<pre><code>$ foo bar --package=@npmcli/foo
234</code></pre>
235<p>Since the <code>--package</code> option comes <em>after</em> the positional arguments, it is treated as an argument to the executed command.</p>
236<p>In contrast, due to npm's argument parsing logic, running this command is different:</p>
237<pre><code>$ npm exec foo@latest bar --package=@npmcli/foo
238</code></pre>
239<p>In this case, npm will parse the <code>--package</code> option first, resolving the
240<code>@npmcli/foo</code> package.
241Then, it will execute the following command in that context:</p>
242<pre><code>$ foo@latest bar
243</code></pre>
244<p>The double-hyphen character is recommended to explicitly tell npm to stop parsing command line options and switches.
245The following command would thus be equivalent to the <code>npx</code> command above:</p>
246<pre><code>$ npm exec -- foo@latest bar --package=@npmcli/foo
247</code></pre>
248<h3 id="examples">Examples</h3>
249<p>Run the version of <code>tap</code> in the local dependencies, with the provided arguments:</p>
250<pre><code>$ npm exec -- tap --bail test/foo.js
251$ npx tap --bail test/foo.js
252</code></pre>
253<p>Run a command <em>other than</em> the command whose name matches the package name by specifying a <code>--package</code> option:</p>
254<pre><code>$ npm exec --package=foo -- bar --bar-argument
255# ~ or ~
256$ npx --package=foo bar --bar-argument
257</code></pre>
258<p>Run an arbitrary shell script, in the context of the current project:</p>
259<pre><code>$ npm x -c 'eslint && say "hooray, lint passed"'
260$ npx -c 'eslint && say "hooray, lint passed"'
261</code></pre>
262<h3 id="compatibility-with-older-npx-versions">Compatibility with Older npx Versions</h3>
263<p>The <code>npx</code> binary was rewritten in npm v7.0.0, and the standalone <code>npx</code> package deprecated at that time.
264<code>npx</code> uses the <code>npm exec</code> 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.</p>
265<p>This resulted in some shifts in its functionality:</p>
266<ul>
267<li>Any <code>npm</code> config value may be provided.</li>
268<li>To prevent security and user-experience problems from mistyping package names, <code>npx</code> prompts before installing anything.
269Suppress this prompt with the <code>-y</code> or <code>--yes</code> option.</li>
270<li>The <code>--no-install</code> option is deprecated, and will be converted to <code>--no</code>.</li>
271<li>Shell fallback functionality is removed, as it is not advisable.</li>
272<li>The <code>-p</code> argument is a shorthand for <code>--parseable</code> in npm, but shorthand for <code>--package</code> in npx.
273This is maintained, but only for the <code>npx</code> executable.</li>
274<li>The <code>--ignore-existing</code> option is removed.
275Locally installed bins are always present in the executed process <code>PATH</code>.</li>
276<li>The <code>--npm</code> option is removed.
277<code>npx</code> will always use the <code>npm</code> it ships with.</li>
278<li>The <code>--node-arg</code> and <code>-n</code> options have been removed.
279Use <a href="https://nodejs.org/api/cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> instead: e.g.,
280<code>NODE_OPTIONS="--trace-warnings --trace-exit" npx foo --random=true</code></li>
281<li>The <code>--always-spawn</code> option is redundant, and thus removed.</li>
282<li>The <code>--shell</code> option is replaced with <code>--script-shell</code>, but maintained in the <code>npx</code> executable for backwards compatibility.</li>
283</ul>
284<h3 id="see-also">See Also</h3>
285<ul>
286<li><a href="../commands/npm-run.html">npm run</a></li>
287<li><a href="../using-npm/scripts.html">npm scripts</a></li>
288<li><a href="../commands/npm-test.html">npm test</a></li>
289<li><a href="../commands/npm-start.html">npm start</a></li>
290<li><a href="../commands/npm-restart.html">npm restart</a></li>
291<li><a href="../commands/npm-stop.html">npm stop</a></li>
292<li><a href="../commands/npm-config.html">npm config</a></li>
293<li><a href="../commands/npm-exec.html">npm exec</a></li>
294</ul></div>
295
296<footer id="edit">
297<a href="https://github.com/npm/cli/edit/latest/docs/lib/content/commands/npx.md">
298<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
299<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
300</svg>
301Edit this page on GitHub
302</a>
303</footer>
304</section>
305
306
307
308</body></html>