.TH "NPM\-PKG" "1" "November 2023" "9.2.0" .SH "NAME" \fBnpm-pkg\fR .SH Synopsis .SH Description .P A command that automates the management of \fBpackage\.json\fP files\. .br \fBnpm pkg\fP provide 3 different sub commands that allow you to modify or retrieve .br values for given object keys in your \fBpackage\.json\fP\|\. .P The syntax to retrieve and set fields is a dot separated representation of .br the nested object properties to be found within your \fBpackage\.json\fP, it's the .br same notation used in \fBnpm view\fP to retrieve information .br from the registry manifest, below you can find more examples on how to use it\. .P Returned values are always in \fBjson\fR format\. .RS 1 .IP \(bu 2 \fBnpm pkg get \fP .P Retrieves a value \fBkey\fP, defined in your \fBpackage\.json\fP file\. .P For example, in order to retrieve the name of the current package, you .br can run: .RS 2 .nf npm pkg get name .fi .RE .P It's also possible to retrieve multiple values at once: .RS 2 .nf npm pkg get name version .fi .RE .P You can view child fields by separating them with a period\. To retrieve .br the value of a test \fBscript\fP value, you would run the following command: .RS 2 .nf npm pkg get scripts\.test .fi .RE .P For fields that are arrays, requesting a non\-numeric field will return .br all of the values from the objects in the list\. For example, to get all .br the contributor emails for a package, you would run: .RS 2 .nf npm pkg get contributors\.email .fi .RE .P You may also use numeric indices in square braces to specifically select .br an item in an array field\. To just get the email address of the first .br contributor in the list, you can run: .RS 2 .nf npm pkg get contributors[0]\.email .fi .RE .P For complex fields you can also name a property in square brackets .br to specifically select a child field\. This is especially helpful .br with the exports object: .RS 2 .nf npm pkg get "exports[\.]\.require" .fi .RE .IP \(bu 2 \fBnpm pkg set =\fP .P Sets a \fBvalue\fP in your \fBpackage\.json\fP based on the \fBfield\fP value\. When .br saving to your \fBpackage\.json\fP file the same set of rules used during .br \fBnpm install\fP and other cli commands that touches the \fBpackage\.json\fP file .br are used, making sure to respect the existing indentation and possibly .br applying some validation prior to saving values to the file\. .P The same syntax used to retrieve values from your package can also be used .br to define new properties or overriding existing ones, below are some .br examples of how the dot separated syntax can be used to edit your .br \fBpackage\.json\fP file\. .P Defining a new bin named \fBmynewcommand\fP in your \fBpackage\.json\fP that points .br to a file \fBcli\.js\fP: .RS 2 .nf npm pkg set bin\.mynewcommand=cli\.js .fi .RE .P Setting multiple fields at once is also possible: .RS 2 .nf npm pkg set description='Awesome package' engines\.node='>=10' .fi .RE .P It's also possible to add to array values, for example to add a new .br contributor entry: .RS 2 .nf npm pkg set contributors[0]\.name='Foo' contributors[0]\.email='foo@bar\.ca' .fi .RE .P You may also append items to the end of an array using the special .br empty bracket notation: .RS 2 .nf npm pkg set contributors[]\.name='Foo' contributors[]\.name='Bar' .fi .RE .P It's also possible to parse values as json prior to saving them to your .br \fBpackage\.json\fP file, for example in order to set a \fB"private": true\fP .br property: .RS 2 .nf npm pkg set private=true \-\-json .fi .RE .P It also enables saving values as numbers: .RS 2 .nf npm pkg set tap\.timeout=60 \-\-json .fi .RE .IP \(bu 2 \fBnpm pkg delete \fP .P Deletes a \fBkey\fP from your \fBpackage\.json\fP .P The same syntax used to set values from your package can also be used .br to remove existing ones\. For example, in order to remove a script named .br build: .RS 2 .nf npm pkg delete scripts\.build .fi .RE .RE .SH Workspaces support .P You can set/get/delete items across your configured workspaces by using the .br \fBworkspace\fP or .br \fBworkspaces\fP config options\. .P For example, setting a \fBfunding\fP value across all configured workspaces .br of a project: .RS 2 .nf npm pkg set funding=https://example\.com \-\-ws .fi .RE .P When using \fBnpm pkg get\fP to retrieve info from your configured workspaces, the .br returned result will be in a json format in which top level keys are the .br names of each workspace, the values of these keys will be the result values .br returned from each of the configured workspaces, e\.g: .RS 2 .nf npm pkg get name version \-\-ws { "a": { "name": "a", "version": "1\.0\.0" }, "b": { "name": "b", "version": "1\.0\.0" } } .fi .RE .SH Configuration .SH See Also .RS 1 .IP \(bu 2 npm install .IP \(bu 2 npm init .IP \(bu 2 npm config .IP \(bu 2 npm set\-script .IP \(bu 2 workspaces .RE