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