1NPM-PKG(1)                                                          NPM-PKG(1)
2
3
4

NAME

6       npm-pkg - Manages your package.json
7
8   Synopsis
9         npm pkg set <key>=<value> [<key>=<value> ...]
10         npm pkg get [<key> [<key> ...]]
11         npm pkg delete <key> [<key> ...]
12         npm pkg set [<array>[<index>].<key>=<value> ...]
13         npm pkg set [<array>[].<key>=<value> ...]
14         npm pkg fix
15
16   Description
17       A  command that automates the management of package.json files. npm pkg
18       provide 3 different sub commands that allow you to modify  or  retrieve
19       values for given object keys in your package.json.
20
21       The syntax to retrieve and set fields is a dot separated representation
22       of the nested object properties to be found within  your  package.json,
23       it's  the  same  notation used in npm help view to retrieve information
24       from the registry manifest, below you can find more examples on how  to
25       use it.
26
27       Returned values are always in json format.
28
29npm pkg get <field>
30
31       Retrieves a value key, defined in your package.json file.
32
33       For  example, in order to retrieve the name of the current package, you
34       can run:
35
36         npm pkg get name
37
38       It's also possible to retrieve multiple values at once:
39
40         npm pkg get name version
41
42       You can view child fields by separating them with a period. To retrieve
43       the value of a test script value, you would run the following command:
44
45         npm pkg get scripts.test
46
47       For  fields that are arrays, requesting a non-numeric field will return
48       all of the values from the objects in the list. For example, to get all
49       the contributor emails for a package, you would run:
50
51         npm pkg get contributors.email
52
53       You  may  also use numeric indices in square braces to specifically se‐
54       lect an item in an array field. To just get the email  address  of  the
55       first contributor in the list, you can run:
56
57         npm pkg get contributors[0].email
58
59       For  complex  fields you can also name a property in square brackets to
60       specifically select a child field. This is especially helpful with  the
61       exports object:
62
63         npm pkg get "exports[.].require"
64
65npm pkg set <field>=<value>
66
67       Sets a value in your package.json based on the field value. When saving
68       to your package.json file the same set of rules used during npm install
69       and  other  cli  commands  that touches the package.json file are used,
70       making sure to respect the existing indentation and  possibly  applying
71       some validation prior to saving values to the file.
72
73       The  same  syntax used to retrieve values from your package can also be
74       used to define new properties or overriding existing  ones,  below  are
75       some  examples of how the dot separated syntax can be used to edit your
76       package.json file.
77
78       Defining a new bin named mynewcommand in your package.json that  points
79       to a file cli.js:
80
81         npm pkg set bin.mynewcommand=cli.js
82
83       Setting multiple fields at once is also possible:
84
85         npm pkg set description='Awesome package' engines.node='>=10'
86
87       It's  also  possible  to  add to array values, for example to add a new
88       contributor entry:
89
90         npm pkg set contributors[0].name='Foo' contributors[0].email='foo@bar.ca'
91
92       You may also append items to the end of  an  array  using  the  special
93       empty bracket notation:
94
95         npm pkg set contributors[].name='Foo' contributors[].name='Bar'
96
97       It's also possible to parse values as json prior to saving them to your
98       package.json file, for example in order to set a "private": true  prop‐
99       erty:
100
101         npm pkg set private=true --json
102
103       It also enables saving values as numbers:
104
105         npm pkg set tap.timeout=60 --json
106
107npm pkg delete <key>
108
109       Deletes a key from your package.json
110
111       The  same  syntax used to set values from your package can also be used
112       to remove existing ones. For example, in order to remove a script named
113       build:
114
115         npm pkg delete scripts.build
116
117npm pkg fix
118
119       Auto corrects common errors in your package.json. npm already does this
120       during publish, which leads to subtle (mostly harmless) differences be‐
121       tween  the contents of your package.json file and the manifest that npm
122       uses during installation.
123
124
125   Workspaces support
126       You can set/get/delete items across your configured workspaces by using
127       the  workspace  ⟨/using-npm/config#workspace⟩  or  workspaces  ⟨/using-
128       npm/config#workspaces⟩ config options.
129
130       For example, setting a funding value across all  configured  workspaces
131       of a project:
132
133         npm pkg set funding=https://example.com --ws
134
135       When   using  npm  pkg  get  to  retrieve  info  from  your  configured
136       workspaces, the returned result will be in a json format in  which  top
137       level  keys  are  the names of each workspace, the values of these keys
138       will be  the  result  values  returned  from  each  of  the  configured
139       workspaces, e.g:
140
141         npm pkg get name version --ws
142         {
143           "a": {
144             "name": "a",
145             "version": "1.0.0"
146           },
147           "b": {
148             "name": "b",
149             "version": "1.0.0"
150           }
151         }
152
153   Configuration
154   force
155       •   Default: false
156
157       •   Type: Boolean
158
159
160       Removes  various  protections  against unfortunate side effects, common
161       mistakes, unnecessary performance degradation, and malicious input.
162
163       •   Allow clobbering non-npm files in global installs.
164
165       •   Allow the npm version command to work on an unclean git repository.
166
167       •   Allow deleting the cache folder with npm cache clean.
168
169       •   Allow installing packages that have an engines declaration  requir‐
170           ing a different version of npm.
171
172       •   Allow  installing packages that have an engines declaration requir‐
173           ing a different version of node, even  if  --engine-strict  is  en‐
174           abled.
175
176       •   Allow  npm  audit fix to install modules outside your stated depen‐
177           dency range (including SemVer-major changes).
178
179       •   Allow unpublishing all versions of a published package.
180
181       •   Allow conflicting peerDependencies to  be  installed  in  the  root
182           project.
183
184       •   Implicitly set --yes during npm init.
185
186       •   Allow clobbering existing values in npm pkg
187
188       •   Allow unpublishing of entire packages (not just a single version).
189
190
191       If  you  don't have a clear idea of what you want to do, it is strongly
192       recommended that you do not use this option!
193
194   json
195       •   Default: false
196
197       •   Type: Boolean
198
199
200       Whether or not to output JSON data, rather than the normal output.
201
202       •   In npm pkg set it enables parsing set values with JSON.parse()  be‐
203           fore saving them to your package.json.
204
205
206       Not supported by all npm commands.
207
208   workspace
209       •   Default:
210
211       •   Type: String (can be set multiple times)
212
213
214       Enable running a command in the context of the configured workspaces of
215       the current project while filtering by running only the workspaces  de‐
216       fined by this configuration option.
217
218       Valid values for the workspace config are either:
219
220       •   Workspace names
221
222       •   Path to a workspace directory
223
224       •   Path  to a parent workspace directory (will result in selecting all
225           workspaces within that folder)
226
227
228       When set for the npm init command, this may be set to the folder  of  a
229       workspace  which does not yet exist, to create the folder and set it up
230       as a brand new workspace within the project.
231
232       This value is not exported to the environment for child processes.
233
234   workspaces
235       •   Default: null
236
237       •   Type: null or Boolean
238
239
240       Set to true to run  the  command  in  the  context  of  all  configured
241       workspaces.
242
243       Explicitly  setting  this  to false will cause commands like install to
244       ignore workspaces altogether. When not set explicitly:
245
246       •   Commands that operate on the node_modules  tree  (install,  update,
247           etc.) will link workspaces into the node_modules folder. - Commands
248           that do other things (test, exec, publish, etc.)  will  operate  on
249           the  root  project,  unless one or more workspaces are specified in
250           the workspace config.
251
252
253       This value is not exported to the environment for child processes.
254

SEE ALSO

256       •   npm help install
257
258       •   npm help init
259
260       •   npm help config
261
262       •   npm help workspaces
263
264
265
266                                 November 2023                      NPM-PKG(1)
Impressum