npm-pkg

Manages your package.json

Table of contents

Synopsis

npm pkg get [<field> [.<subfield> ...]]
npm pkg set <field>=<value> [.<subfield>=<value> ...]
npm pkg delete <field> [.<subfield> ...]

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

Enable running a command in the context of all the configured workspaces.

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

See Also