You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/cli/v11/commands/npm-install.mdx
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,8 @@ Even if you never publish your package, you can still get a lot of benefits of u
121
121
122
122
In most cases, this will install the version of the modules tagged as `latest` on the npm registry.
123
123
124
+
**Note:** When installing by name without specifying a version or tag, npm prioritizes versions that match the current Node.js version based on the package's `engines` field. If the `latest` tag points to a version incompatible with your current Node.js version, npm will install the newest compatible version instead. To install a specific version regardless of `engines` compatibility, explicitly specify the version or tag: `npm install <name>@latest`.
125
+
124
126
Example:
125
127
126
128
```bash
@@ -209,6 +211,15 @@ Even if you never publish your package, you can still get a lot of benefits of u
209
211
npm install @myorg/privatepackage@"16 - 17"
210
212
```
211
213
214
+
**Prerelease versions:** By default, version ranges only match stable versions. To include prerelease versions, they must be explicitly specified in the range. Prerelease versions are tied to a specific version triple (major.minor.patch). For example, `^1.2.3-beta.1` will only match prereleases for `1.2.x`, not `1.3.x`. To match all prereleases for a major version, use a range like `^1.0.0-0`, which will include all `1.x.x` prereleases.
215
+
216
+
Example:
217
+
218
+
```bash
219
+
npm install package@^1.2.3-beta.1 # Matches 1.2.3-beta.1, 1.2.3-beta.2, 1.2.4-beta.1, etc.
220
+
npm install package@^1.0.0-0 # Matches all 1.x.x prereleases and stable versions
221
+
```
222
+
212
223
-`npm install <git remote url>`:
213
224
214
225
Installs the package from the hosted git provider, cloning it with `git`. For a full git remote url, only that URL will be attempted.
The `--tag` argument will apply to all of the specified install targets. If a tag with the given name exists, the tagged version is preferred over newer versions.
314
325
326
+
**Note:** The `--tag` option only affects packages specified on the command line. It does not override version ranges specified in`package.json`. For example, if`package.json` specifies `"foo": "^1.0.0"` and you run `npm install --tag beta`, npm will still install a version matching `^1.0.0` even if the `beta` tag points to a different version. To install a tagged version, specify the package explicitly: `npm install foo@beta`.
327
+
315
328
The `--dry-run` argument will report in the usual way what the install would have done without actually installing anything.
316
329
317
330
The `--package-lock-only` argument will only update the `package-lock.json`, instead of checking `node_modules` and downloading dependencies.
Copy file name to clipboardExpand all lines: content/cli/v11/commands/npm-ls.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ Note: to get a "bottoms up" view of why a given package is included in the tree
52
52
Positional arguments are `name@version-range` identifiers, which will limit the results to only the paths to the packages named. Note that nested packages will _also_ show the paths to the specified packages. For example, running `npm ls promzard` in npm's source tree will show:
@@ -49,27 +49,21 @@ Note: This command is unaware of workspaces.
49
49
50
50
This lets you list, create and revoke authentication tokens.
51
51
52
-
-`npm token list`: Shows a table of all active authentication tokens. You can request this as JSON with `--json` or tab-separated values with `--parseable`.
52
+
#### Listing tokens
53
53
54
-
```
55
-
Read only token npm_1f… with id 7f3134 created 2017-10-21
56
-
57
-
Publish token npm_af… with id c03241 created 2017-10-02
58
-
with IP Whitelist: 192.168.0.1/24
54
+
When listing tokens, an abbreviated token will be displayed. For security purposes the full token is not displayed.
59
55
60
-
Publish token npm_… with id e0cf92 created 2017-10-02
56
+
#### Generating tokens
61
57
62
-
```
58
+
When generating tokens, you will be prompted you for your password and, if you have two-factor authentication enabled, an otp.
63
59
64
-
-`npm token create [--read-only] [--cidr=<cidr-ranges>]`: Create a new authentication token. It can be `--read-only`, or accept a list of [CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) ranges with which to limit use of this token. This will prompt you for your password, and, if you have two-factor authentication enabled, an otp.
60
+
Please refer to the [docs website](https://docs.npmjs.com/creating-and-viewing-access-tokens) for more information on generating tokens for CI/CD.
65
61
66
-
Currently, the cli cannot generate automation tokens. Please refer to the [docs website](https://docs.npmjs.com/creating-and-viewing-access-tokens) for more information on generating automation tokens.
62
+
#### Revoking tokens
67
63
68
-
```
69
-
Created publish token a73c9572-f1b9-8983-983d-ba3ac3cc913d
70
-
```
64
+
When revoking a token, you can use the full token (e.g. what you get back from `npm token create`, or as can be found in an `.npmrc` file), or a truncated id. If the given truncated id is not distinct enough to differentiate between multiple existing tokens, you will need to use enough of the id to allow npm to distinguish between them. Full token ids can be found on the [npm website](https://www.npmjs.com), or in the `--parseable` or `--json` output of `npm token list`. This command will NOT accept the truncated token found in the normal `npm token list` output.
71
65
72
-
-`npm token revoke <token|id>`: Immediately removes an authentication token from the registry. You will no longer be able to use it. This can accept both complete tokens (such as those you get back from `npm token create`, and those found in your `.npmrc`), and ids as seen in the parseable or json output of `npm token list`. This will NOT accept the truncated token found in the normal `npm token list` output.
66
+
A revoked token will immediately be removed from the registry and you will no longer be able to use it.
73
67
74
68
### Configuration
75
69
@@ -99,7 +93,7 @@ When creating a Granular Access Token with `npm token create`, this sets the exp
99
93
- Default:
100
94
- Type: null or String (can be set multiple times)
101
95
102
-
When creating a Granular Access Token with `npm token create`, this limits the token access to specific packages. Provide a comma-separated list of package names.
96
+
When creating a Granular Access Token with `npm token create`, this limits the token access to specific packages.
103
97
104
98
#### `packages-all`
105
99
@@ -113,14 +107,14 @@ When creating a Granular Access Token with `npm token create`, grants the token
113
107
- Default: null
114
108
- Type: null or String (can be set multiple times)
115
109
116
-
When creating a Granular Access Token with `npm token create`, this limits the token access to specific scopes. Provide a comma-separated list of scope names (with or without @ prefix).
110
+
When creating a Granular Access Token with `npm token create`, this limits the token access to specific scopes. Provide a scope name (with or without @ prefix).
117
111
118
112
#### `orgs`
119
113
120
114
- Default: null
121
115
- Type: null or String (can be set multiple times)
122
116
123
-
When creating a Granular Access Token with `npm token create`, this limits the token access to specific organizations. Provide a comma-separated list of organization names.
117
+
When creating a Granular Access Token with `npm token create`, this limits the token access to specific organizations.
Copy file name to clipboardExpand all lines: content/cli/v11/commands/npm-version.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,8 +167,12 @@ Run this in a package directory to bump the version and write the new data back
167
167
168
168
The `newversion` argument should be a valid semver string, a valid second argument to [semver.inc](https://github.com/npm/node-semver#functions) (one of `patch`, `minor`, `major`, `prepatch`, `preminor`, `premajor`, `prerelease`), or `from-git`. In the second case, the existing version will be incremented by 1 in the specified field. `from-git` will try to read the latest git tag, and use that as the new npm version.
169
169
170
+
**Note:** If the current version is a prerelease version, `patch` will simply remove the prerelease suffix without incrementing the patch version number. For example, `1.2.0-5` becomes `1.2.0` with `npm version patch`, not `1.2.1`.
171
+
170
172
If run in a git repo, it will also create a version commit and tag. This behavior is controlled by `git-tag-version` (see below), and can be disabled on the command line by running `npm --no-git-tag-version version`. It will fail if the working directory is not clean, unless the `-f` or `--force` flag is set.
171
173
174
+
**Note:** Git integration requires a reasonably recent version of git (2.0.0 or later is recommended). If you encounter issues with git commands, ensure your git installation is up to date.
175
+
172
176
If supplied with `-m` or [`--message` config](/cli/v11/using-npm/config#message) option, npm will use it as a commit message when creating a version commit. If the `message` config contains `%s` then that will be replaced with the resulting version number. For example:
Copy file name to clipboardExpand all lines: content/cli/v11/commands/npm-view.mdx
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,20 @@ If the field value you are querying for is a property of an object, you should r
97
97
npm view express time'[4.8.0]'
98
98
```
99
99
100
+
Note: When accessing object properties that contain special characters or numeric keys, you need to use quotes around the key name. For example, to get the publish time of a specific version:
101
+
102
+
```bash
103
+
npm view express "time[4.17.1]"
104
+
```
105
+
106
+
Without quotes, the shell may interpret the square brackets as glob patterns, causing the command to fail. You can also access the time field for a specific version by specifying the version in the package descriptor:
107
+
108
+
```bash
109
+
npm view express@4.17.1 time
110
+
```
111
+
112
+
This will return all version-time pairs, but the context will be for that specific version.
113
+
100
114
Multiple fields may be specified, and will be printed one after another. For example, to get all the contributor names and email addresses, you can do this:
101
115
102
116
```bash
@@ -121,6 +135,56 @@ To show the `connect` package version history, you can do this:
121
135
npm view connect versions
122
136
```
123
137
138
+
### Field Access Patterns
139
+
140
+
The `npm view` command supports different ways to access nested fields and array elements in package metadata. Understanding these patterns makes it easier to extract specific information.
141
+
142
+
#### Nested Object Fields
143
+
144
+
Use dot notation to access nested object fields:
145
+
146
+
```bash
147
+
# Access nested properties
148
+
npm view npm repository.url
149
+
npm view express bugs.url
150
+
```
151
+
152
+
#### Array Element Access
153
+
154
+
For arrays, use numeric indices in square brackets to access specific elements:
155
+
156
+
```bash
157
+
# Get the first contributor's email
158
+
npm view express contributors[0].email
159
+
160
+
# Get the second maintainer's name
161
+
npm view express maintainers[1].name
162
+
```
163
+
164
+
#### Object Property Access
165
+
166
+
For object properties (like accessing specific versions in the `time` field), use bracket notation with the property name in quotes:
167
+
168
+
```bash
169
+
# Get publish time for a specific version
170
+
npm view express "time[4.17.1]"
171
+
172
+
# Get dist-tags
173
+
npm view express "dist-tags.latest"
174
+
```
175
+
176
+
#### Extracting Fields from Arrays
177
+
178
+
Request a non-numeric field on an array to get all values from objects in the list:
This command allows you to run an arbitrary command from an npm package (either one installed locally, or fetched remotely), in a similar context as running it via `npm run`.
36
36
37
+
Run this command to execute a package's binary. Any options and arguments after the package name are passed directly to the executed command, not to npx itself. For example, `npx create-react-app my-app --template typescript` will pass `my-app` and `--template typescript` to the `create-react-app` command. To see what options a specific package accepts, consult that package's documentation (e.g., at npmjs.com or in its repository).
38
+
37
39
Whatever packages are specified by the `--package` option will be provided in the `PATH` of the executed command, along with any locally installed package executables. The `--package` option may be specified multiple times, to execute the supplied command in an environment where all specified packages are available.
38
40
39
41
If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the `PATH` environment variable in the executed process. A prompt is printed (which can be suppressed by providing either `--yes` or `--no`).
Copy file name to clipboardExpand all lines: content/cli/v11/configuring-npm/package-json.mdx
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -325,6 +325,12 @@ For most modules, it makes the most sense to have a main script and often not mu
325
325
326
326
If `main` is not set, it defaults to `index.js` in the package's root folder.
327
327
328
+
### type
329
+
330
+
The `type` field defines how Node.js should interpret `.js` files in your package. This field is not used by npm.
331
+
332
+
See the [Node.js documentation on the type field](https://nodejs.org/api/packages.html#type) for more information.
333
+
328
334
### browser
329
335
330
336
If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren't available in Node.js modules. (e.g. `window`)
@@ -470,6 +476,19 @@ For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
470
476
}
471
477
```
472
478
479
+
**Note on normalization:** When you publish a package, npm normalizes the `repository` field to the full object format with a `url` property. If you use a shorthand format (like `"npm/example"`), you'll see a warning during `npm publish` indicating that the field was auto-corrected. While the shorthand format currently works, it's recommended to use the full object format in your `package.json` to avoid warnings and ensure future compatibility:
480
+
481
+
```json
482
+
{
483
+
"repository": {
484
+
"type": "git",
485
+
"url": "git+https://github.com/npm/example.git"
486
+
}
487
+
}
488
+
```
489
+
490
+
You can run `npm pkg fix` to automatically convert shorthand formats to the normalized object format.
491
+
473
492
If the `package.json` for your package is not in the root directory (for example if it is part of a monorepo), you can specify the directory in which it lives:
474
493
475
494
```json
@@ -488,6 +507,20 @@ The "scripts" property is a dictionary containing script commands that are run a
488
507
489
508
See [`scripts`](/cli/v11/using-npm/scripts) to find out more about writing package scripts.
490
509
510
+
### gypfile
511
+
512
+
If you have a binding.gyp file in the root of your package and you have not defined your own `install` or `preinstall` scripts, npm will default to building your module using node-gyp.
513
+
514
+
To prevent npm from automatically building your module with node-gyp, set `gypfile` to `false`:
515
+
516
+
```json
517
+
{
518
+
"gypfile": false
519
+
}
520
+
```
521
+
522
+
This is useful for packages that include native addons but want to handle the build process differently, or packages that have a binding.gyp file but should not be built as a native addon.
523
+
491
524
### config
492
525
493
526
A "config" object can be used to set configuration parameters used in package scripts that persist across upgrades. For instance, if a package had the following:
@@ -853,6 +886,52 @@ You may not set an override for a package that you directly depend on unless bot
853
886
}
854
887
```
855
888
889
+
#### Replacing a dependency with a fork
890
+
891
+
You can replace a package with a different package or fork using several methods:
892
+
893
+
**Using the `npm:` prefix to replace with a different package name:**
894
+
895
+
```json
896
+
{
897
+
"overrides": {
898
+
"package-name": "npm:@scope/forked-package@1.0.0"
899
+
}
900
+
}
901
+
```
902
+
903
+
**Using a GitHub repository (supports branches, tags, or commit hashes):**
Copy file name to clipboardExpand all lines: content/cli/v11/configuring-npm/package-lock-json.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,14 +136,16 @@ npm v7 ignores this section entirely if a `packages` section is present, but doe
136
136
137
137
Dependency objects have the following fields:
138
138
139
-
- version: a specifier that varies depending on the nature of the package, and is usable in fetching a new copy of it.
139
+
- version: a specifier that varies depending on the nature of the package, and is usable in fetching a new copy of it. Note that for peer dependencies that are not installed, or optional dependencies that are not installed, this field may be omitted.
140
140
- bundled dependencies: Regardless of source, this is a version number that is purely for informational purposes.
141
141
- registry sources: This is a version number. (eg, `1.2.3`)
142
142
- git sources: This is a git specifier with resolved committish. (eg, `git+https://example.com/foo/bar#115311855adb0789a0466714ed48a1499ffea97e`)
143
143
- http tarball sources: This is the URL of the tarball. (eg, `https://example.com/example-1.3.0.tgz`)
144
144
- local tarball sources: This is the file URL of the tarball. (eg `file:///opt/storage/example-1.3.0.tgz`)
145
145
- local link sources: This is the file URL of the link. (eg `file:libs/our-module`)
146
146
147
+
**Note:** The `version` field may be omitted for certain types of dependencies, such as optional peer dependencies that are not installed. In these cases, only metadata fields like `dev`, `optional`, and `peer` will be present.
148
+
147
149
- integrity: A `sha512` or `sha1`[Standard Subresource Integrity](https://w3c.github.io/webappsec/specs/subresourceintegrity/) string for the artifact that was unpacked in this location. For git dependencies, this is the commit sha.
148
150
149
151
- resolved: For registry sources this is path of the tarball relative to the registry URL. If the tarball URL isn't on the same server as the registry URL then this is a complete URL. `registry.npmjs.org` is a magic value meaning "the currently configured registry".
0 commit comments