npm-pkg @10.8.2

Manages your package.json

Table of contents

Synopsis

npm pkg set <key>=<value> [<key>=<value> ...]
npm pkg get [<key> [<key> ...]]
npm pkg delete <key> [<key> ...]
npm pkg set [<array>[<index>].<key>=<value> ...]
npm pkg set [<array>[].<key>=<value> ...]
npm pkg fix

Description

A command that automates the management of package.json files. npm pkg provide 3 different sub commands that allow you to modify or retrieve values for given object keys in your package.json.

The syntax to retrieve and set fields is a dot separated representation of the nested object properties to be found within your package.json, it's the same notation used in npm view to retrieve information from the registry manifest, below you can find more examples on how to use it.

Returned values are always in json format.

Workspaces support

You can set/get/delete items across your configured workspaces by using the workspace or workspaces config options.

For example, setting a funding value across all configured workspaces of a project:

npm pkg set funding=https://example.com --ws

When using npm pkg get 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:

npm pkg get name version --ws
{
  "a": {
    "name": "a",
    "version": "1.0.0"
  },
  "b": {
    "name": "b",
    "version": "1.0.0"
  }
}

Configuration

force

Removes various protections against unfortunate side effects, common mistakes, unnecessary performance degradation, and malicious input.

If you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option!

json

Whether or not to output JSON data, rather than the normal output.

Not supported by all npm commands.

workspace

Enable 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.

Valid values for the workspace config are either:

When set for the npm init 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.

This value is not exported to the environment for child processes.

workspaces

Set to true to run the command in the context of all configured workspaces.

Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:

This value is not exported to the environment for child processes.

See Also