1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>npm-pkg</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
116footer#edit {
117    border-top: solid 1px #e1e4e8;
118    margin: 3em 0 4em 0;
119    padding-top: 2em;
120}
121</style>
122</head>
123<body>
124<div id="banner">
125<div id="rainbar"></div>
126<div id="logobar">
127<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
128<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
129<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
130</svg>
131<div class="title">
132npm command-line interface
133</div>
134</div>
135</div>
136
137<section id="content">
138<header class="title">
139<h1 id="npm-pkg">npm-pkg</h1>
140<span class="description">Manages your package.json</span>
141</header>
142
143<section id="table_of_contents">
144<h2 id="table-of-contents">Table of contents</h2>
145<div id="_table_of_contents"><ul><li><a href="#see-also">See Also</a></li></ul></div>
146</section>
147
148<div id="_content"><h3 id="synopsis">Synopsis</h3>
149<pre><code class="language-bash">npm pkg set &lt;key&gt;=&lt;value&gt; [&lt;key&gt;=&lt;value&gt; ...]
150npm pkg get [&lt;key&gt; [&lt;key&gt; ...]]
151npm pkg delete &lt;key&gt; [&lt;key&gt; ...]
152npm pkg set [&lt;array&gt;[&lt;index&gt;].&lt;key&gt;=&lt;value&gt; ...]
153npm pkg set [&lt;array&gt;[].&lt;key&gt;=&lt;value&gt; ...]
154npm pkg fix
155</code></pre>
156<h3 id="description">Description</h3>
157<p>A command that automates the management of <code>package.json</code> files.
158<code>npm pkg</code> provide 3 different sub commands that allow you to modify or retrieve
159values for given object keys in your <code>package.json</code>.</p>
160<p>The syntax to retrieve and set fields is a dot separated representation of
161the nested object properties to be found within your <code>package.json</code>, it's the
162same notation used in <a href="../commands/npm-view.html"><code>npm view</code></a> to retrieve information
163from the registry manifest, below you can find more examples on how to use it.</p>
164<p>Returned values are always in <strong>json</strong> format.</p>
165<ul>
166<li>
167<p><code>npm pkg get &lt;field&gt;</code></p>
168<p>Retrieves a value <code>key</code>, defined in your <code>package.json</code> file.</p>
169<p>For example, in order to retrieve the name of the current package, you
170can run:</p>
171<pre><code class="language-bash">npm pkg get name
172</code></pre>
173<p>It's also possible to retrieve multiple values at once:</p>
174<pre><code class="language-bash">npm pkg get name version
175</code></pre>
176<p>You can view child fields by separating them with a period. To retrieve
177the value of a test <code>script</code> value, you would run the following command:</p>
178<pre><code class="language-bash">npm pkg get scripts.test
179</code></pre>
180<p>For fields that are arrays, requesting a non-numeric field will return
181all of the values from the objects in the list. For example, to get all
182the contributor emails for a package, you would run:</p>
183<pre><code class="language-bash">npm pkg get contributors.email
184</code></pre>
185<p>You may also use numeric indices in square braces to specifically select
186an item in an array field. To just get the email address of the first
187contributor in the list, you can run:</p>
188<pre><code class="language-bash">npm pkg get contributors[0].email
189</code></pre>
190<p>For complex fields you can also name a property in square brackets
191to specifically select a child field. This is especially helpful
192with the exports object:</p>
193<pre><code class="language-bash">npm pkg get "exports[.].require"
194</code></pre>
195</li>
196<li>
197<p><code>npm pkg set &lt;field&gt;=&lt;value&gt;</code></p>
198<p>Sets a <code>value</code> in your <code>package.json</code> based on the <code>field</code> value. When
199saving to your <code>package.json</code> file the same set of rules used during
200<code>npm install</code> and other cli commands that touches the <code>package.json</code> file
201are used, making sure to respect the existing indentation and possibly
202applying some validation prior to saving values to the file.</p>
203<p>The same syntax used to retrieve values from your package can also be used
204to define new properties or overriding existing ones, below are some
205examples of how the dot separated syntax can be used to edit your
206<code>package.json</code> file.</p>
207<p>Defining a new bin named <code>mynewcommand</code> in your <code>package.json</code> that points
208to a file <code>cli.js</code>:</p>
209<pre><code class="language-bash">npm pkg set bin.mynewcommand=cli.js
210</code></pre>
211<p>Setting multiple fields at once is also possible:</p>
212<pre><code class="language-bash">npm pkg set description='Awesome package' engines.node='&gt;=10'
213</code></pre>
214<p>It's also possible to add to array values, for example to add a new
215contributor entry:</p>
216<pre><code class="language-bash">npm pkg set contributors[0].name='Foo' contributors[0].email='foo@bar.ca'
217</code></pre>
218<p>You may also append items to the end of an array using the special
219empty bracket notation:</p>
220<pre><code class="language-bash">npm pkg set contributors[].name='Foo' contributors[].name='Bar'
221</code></pre>
222<p>It's also possible to parse values as json prior to saving them to your
223<code>package.json</code> file, for example in order to set a <code>"private": true</code>
224property:</p>
225<pre><code class="language-bash">npm pkg set private=true --json
226</code></pre>
227<p>It also enables saving values as numbers:</p>
228<pre><code class="language-bash">npm pkg set tap.timeout=60 --json
229</code></pre>
230</li>
231<li>
232<p><code>npm pkg delete &lt;key&gt;</code></p>
233<p>Deletes a <code>key</code> from your <code>package.json</code></p>
234<p>The same syntax used to set values from your package can also be used
235to remove existing ones. For example, in order to remove a script named
236build:</p>
237<pre><code class="language-bash">npm pkg delete scripts.build
238</code></pre>
239</li>
240<li>
241<p><code>npm pkg fix</code></p>
242<p>Auto corrects common errors in your <code>package.json</code>.  npm already
243does this during <code>publish</code>, which leads to subtle (mostly harmless)
244differences between the contents of your <code>package.json</code> file and the
245manifest that npm uses during installation.</p>
246</li>
247</ul>
248<h3 id="workspaces-support">Workspaces support</h3>
249<p>You can set/get/delete items across your configured workspaces by using the
250<a href="../using-npm/config#workspace.html"><code>workspace</code></a> or
251<a href="../using-npm/config#workspaces.html"><code>workspaces</code></a> config options.</p>
252<p>For example, setting a <code>funding</code> value across all configured workspaces
253of a project:</p>
254<pre><code class="language-bash">npm pkg set funding=https://example.com --ws
255</code></pre>
256<p>When using <code>npm pkg get</code> to retrieve info from your configured workspaces, the
257returned result will be in a json format in which top level keys are the
258names of each workspace, the values of these keys will be the result values
259returned from each of the configured workspaces, e.g:</p>
260<pre><code>npm pkg get name version --ws
261{
262  "a": {
263    "name": "a",
264    "version": "1.0.0"
265  },
266  "b": {
267    "name": "b",
268    "version": "1.0.0"
269  }
270}
271</code></pre>
272<h3 id="configuration">Configuration</h3>
273<h4 id="force"><code>force</code></h4>
274<ul>
275<li>Default: false</li>
276<li>Type: Boolean</li>
277</ul>
278<p>Removes various protections against unfortunate side effects, common
279mistakes, unnecessary performance degradation, and malicious input.</p>
280<ul>
281<li>Allow clobbering non-npm files in global installs.</li>
282<li>Allow the <code>npm version</code> command to work on an unclean git repository.</li>
283<li>Allow deleting the cache folder with <code>npm cache clean</code>.</li>
284<li>Allow installing packages that have an <code>engines</code> declaration requiring a
285different version of npm.</li>
286<li>Allow installing packages that have an <code>engines</code> declaration requiring a
287different version of <code>node</code>, even if <code>--engine-strict</code> is enabled.</li>
288<li>Allow <code>npm audit fix</code> to install modules outside your stated dependency
289range (including SemVer-major changes).</li>
290<li>Allow unpublishing all versions of a published package.</li>
291<li>Allow conflicting peerDependencies to be installed in the root project.</li>
292<li>Implicitly set <code>--yes</code> during <code>npm init</code>.</li>
293<li>Allow clobbering existing values in <code>npm pkg</code></li>
294<li>Allow unpublishing of entire packages (not just a single version).</li>
295</ul>
296<p>If you don't have a clear idea of what you want to do, it is strongly
297recommended that you do not use this option!</p>
298<h4 id="json"><code>json</code></h4>
299<ul>
300<li>Default: false</li>
301<li>Type: Boolean</li>
302</ul>
303<p>Whether or not to output JSON data, rather than the normal output.</p>
304<ul>
305<li>In <code>npm pkg set</code> it enables parsing set values with JSON.parse() before
306saving them to your <code>package.json</code>.</li>
307</ul>
308<p>Not supported by all npm commands.</p>
309<h4 id="workspace"><code>workspace</code></h4>
310<ul>
311<li>Default:</li>
312<li>Type: String (can be set multiple times)</li>
313</ul>
314<p>Enable running a command in the context of the configured workspaces of the
315current project while filtering by running only the workspaces defined by
316this configuration option.</p>
317<p>Valid values for the <code>workspace</code> config are either:</p>
318<ul>
319<li>Workspace names</li>
320<li>Path to a workspace directory</li>
321<li>Path to a parent workspace directory (will result in selecting all
322workspaces within that folder)</li>
323</ul>
324<p>When set for the <code>npm init</code> command, this may be set to the folder of a
325workspace which does not yet exist, to create the folder and set it up as a
326brand new workspace within the project.</p>
327<p>This value is not exported to the environment for child processes.</p>
328<h4 id="workspaces"><code>workspaces</code></h4>
329<ul>
330<li>Default: null</li>
331<li>Type: null or Boolean</li>
332</ul>
333<p>Set to true to run the command in the context of <strong>all</strong> configured
334workspaces.</p>
335<p>Explicitly setting this to false will cause commands like <code>install</code> to
336ignore workspaces altogether. When not set explicitly:</p>
337<ul>
338<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
339will link workspaces into the <code>node_modules</code> folder. - Commands that do
340other things (test, exec, publish, etc.) will operate on the root project,
341<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
342</ul>
343<p>This value is not exported to the environment for child processes.</p>
344<h2 id="see-also">See Also</h2>
345<ul>
346<li><a href="../commands/npm-install.html">npm install</a></li>
347<li><a href="../commands/npm-init.html">npm init</a></li>
348<li><a href="../commands/npm-config.html">npm config</a></li>
349<li><a href="../using-npm/workspaces.html">workspaces</a></li>
350</ul></div>
351
352<footer id="edit">
353<a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-pkg.md">
354<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
355<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>
356</svg>
357Edit this page on GitHub
358</a>
359</footer>
360</section>
361
362
363
364</body></html>