Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
npm-install.md808 linesDownload Raw Back to commands
1---
2title: npm-install
3section: 1
4description: Install a package
5---
6
7### Synopsis
8
9```bash
10npm install [<package-spec> ...]
11
12aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
13```
14
15### Description
16
17This command installs a package and any packages that it depends on.
18If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:
19
20* `npm-shrinkwrap.json`
21* `package-lock.json`
22* `yarn.lock`
23
24See [package-lock.json](/configuring-npm/package-lock-json) and [`npm shrinkwrap`](/commands/npm-shrinkwrap).
25
26#### How `npm install` uses `package-lock.json`
27
28When you run `npm install` without arguments, npm compares `package.json` and `package-lock.json`:
29
30* **If the lockfile's resolved versions satisfy the `package.json` ranges:** npm uses the exact versions from `package-lock.json` to ensure reproducible builds across environments.
31
32* **If the ranges don't match:** npm resolves new versions that satisfy the `package.json` ranges and updates `package-lock.json` accordingly. This happens when you modify version ranges in `package.json` (e.g., changing `^7.0.0` to `^8.0.0`). Note that changing a range within the same major version (e.g., `^7.0.0` to `^7.1.0`) will only update the metadata in the lockfile if the currently installed version still satisfies the new range.
33
34In essence, `package-lock.json` locks your dependencies to specific versions, but `package.json` is the source of truth for acceptable version ranges. When the lockfile's versions satisfy the `package.json` ranges, the lockfile wins. When they conflict, `package.json` wins and the lockfile is updated.
35
36If you want to install packages while ensuring that `package.json` is not modified and that both files are strictly in sync, use [`npm ci`](/commands/npm-ci) instead.
37
38A `package` is:
39
40* a) a folder containing a program described by a [`package.json`](/configuring-npm/package-json) file
41* b) a gzipped tarball containing (a)
42* c) a url that resolves to (b)
43* d) a `<name>@<version>` that is published on the registry (see [`registry`](/using-npm/registry)) with (c)
44* e) a `<name>@<tag>` (see [`npm dist-tag`](/commands/npm-dist-tag)) that points to (d)
45* f) a `<name>` that has a "latest" tag satisfying (e)
46* g) a `<git remote url>` that resolves to (a)
47
48Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).
49
50
51* `npm install` (in a package directory, no arguments):
52
53    Install the dependencies to the local `node_modules` folder.
54
55    In global mode (ie, with `-g` or `--global` appended to the command), it installs the current package context (ie, the current working directory) as a global package.
56
57    By default, `npm install` will install all modules listed as dependencies in [`package.json`](/configuring-npm/package-json).
58
59    With the `--production` flag (or when the `NODE_ENV` environment variable is set to `production`), npm will not install modules listed in `devDependencies`.
60    To install all modules listed in both `dependencies` and `devDependencies` when `NODE_ENV` environment variable is set to `production`, you can use `--production=false`.
61
62    > NOTE: The `--production` flag has no particular meaning when adding a dependency to a project.
63
64* `npm install <folder>`:
65
66    If `<folder>` sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-level `node_modules` as they would for other types of dependencies.
67    If `<folder>` sits outside the root of your project, *npm will not install the package dependencies* in the directory `<folder>`, but it will create a symlink to `<folder>`.
68
69    > NOTE: If you want to install the content of a directory like a package from the registry instead of creating a link, you would need to use the `--install-links` option.
70
71    Example:
72
73    ```bash
74    npm install ../../other-package --install-links
75    npm install ./sub-package
76    ```
77
78* `npm install <tarball file>`:
79
80    Install a package that is sitting on the filesystem.
81    Note: if you just want to link a dev directory into your npm root, you can do this more easily by using [`npm link`](/commands/npm-link).
82
83    Tarball requirements:
84    * The filename *must* use `.tar`, `.tar.gz`, or `.tgz` as the extension.
85    * The package contents should reside in a subfolder inside the tarball (usually it is called `package/`).
86      npm strips one directory layer when installing the package (an equivalent of `tar x --strip-components=1` is run).
87    * The package must contain a `package.json` file with `name` and `version` properties.
88
89    Example:
90
91    ```bash
92    npm install ./package.tgz
93    ```
94
95* `npm install <tarball url>`:
96
97    Fetch the tarball url, and then install it.
98    In order to distinguish between this and other options, the argument must start with "http://" or "https://"
99
100    Example:
101
102    ```bash
103    npm install https://github.com/indexzero/forever/tarball/v0.5.6
104    ```
105
106* `npm install [<@scope>/]<name>`:
107
108    Do a `<name>@<tag>` install, where `<tag>` is the "tag" config.
109    (See [`config`](/using-npm/config#tag).
110    The config's default value is `latest`.)
111
112    In most cases, this will install the version of the modules tagged as `latest` on the npm registry.
113
114    **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`.
115
116    Example:
117
118    ```bash
119    npm install sax
120    ```
121
122    `npm install` saves any specified packages into `dependencies` by default.
123    Additionally, you can control where and how they get saved with some additional flags:
124
125    * `-P, --save-prod`: Package will appear in your `dependencies`.
126      This is the default unless `-D` or `-O` are present.
127
128    * `-D, --save-dev`: Package will appear in your `devDependencies`.
129
130    * `--save-peer`: Package will appear in your `peerDependencies`.
131
132    * `-O, --save-optional`: Package will appear in your
133      `optionalDependencies`.
134
135    * `--no-save`: Prevents saving to `dependencies`.
136
137    When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:
138
139    * `-E, --save-exact`: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.
140
141    * `-B, --save-bundle`: Saved dependencies will also be added to your `bundleDependencies` list.
142
143    Further, if you have an `npm-shrinkwrap.json` or `package-lock.json` then it will be updated as well.
144
145    `<scope>` is optional.
146    The package will be downloaded from the registry associated with the specified scope.
147    If no registry is associated with the given scope the default registry is assumed.
148    See [`scope`](/using-npm/scope).
149
150    Note: if you do not include the @-symbol on your scope name, npm will interpret this as a GitHub repository instead, see below.
151    Scopes names must also be followed by a slash.
152
153    Examples:
154
155    ```bash
156    npm install sax
157    npm install githubname/reponame
158    npm install @myorg/privatepackage
159    npm install node-tap --save-dev
160    npm install dtrace-provider --save-optional
161    npm install readable-stream --save-exact
162    npm install ansi-regex --save-bundle
163    ```
164
165* `npm install <alias>@npm:<name>`:
166
167    Install a package under a custom alias.
168    Allows multiple versions of a same-name package side-by-side, more convenient import names for packages with otherwise long ones, and using git forks replacements or forked npm packages as replacements.
169    Aliasing works only on your project and does not rename packages in transitive dependencies.
170    Aliases should follow the naming conventions stated in [`validate-npm-package-name`](https://www.npmjs.com/package/validate-npm-package-name#naming-rules).
171
172    Examples:
173
174    ```bash
175    npm install my-react@npm:react
176    npm install jquery2@npm:jquery@2
177    npm install jquery3@npm:jquery@3
178    npm install npa@npm:npm-package-arg
179    ```
180
181* `npm install [<@scope>/]<name>@<tag>`:
182
183    Install the version of the package that is referenced by the specified tag.
184    If the tag does not exist in the registry data for that package, then this will fail.
185
186    Example:
187
188    ```bash
189    npm install sax@latest
190    npm install @myorg/mypackage@latest
191    ```
192
193* `npm install [<@scope>/]<name>@<version>`:
194
195    Install the specified version of the package.
196    This will fail if the version has not been published to the registry.
197
198    Example:
199
200    ```bash
201    npm install sax@0.1.1
202    npm install @myorg/privatepackage@1.5.0
203    ```
204
205* `npm install [<@scope>/]<name>@<version range>`:
206
207    Install a version of the package matching the specified version range.
208    This will follow the same rules for resolving dependencies described in [`package.json`](/configuring-npm/package-json).
209
210    Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.
211
212    Example:
213
214    ```bash
215    npm install sax@">=0.1.0 <0.2.0"
216    npm install @myorg/privatepackage@"16 - 17"
217    ```
218
219    **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.
220
221    Example:
222
223    ```bash
224    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.
225    npm install package@^1.0.0-0       # Matches all 1.x.x prereleases and stable versions
226    ```
227
228* `npm install <git remote url>`:
229
230    Installs the package from the hosted git provider, cloning it with `git`.
231    For a full git remote url, only that URL will be attempted.
232
233    ```bash
234    <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
235    ```
236
237    `<protocol>` is one of `git`, `git+ssh`, `git+http`, `git+https`, or
238    `git+file`.
239
240    If `#<commit-ish>` is provided, it will be used to clone exactly that commit.
241    If the commit-ish has the format `#semver:<semver>`, `<semver>` can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency.
242    If neither `#<commit-ish>` or `#semver:<semver>` is specified, then the default branch of the repository is used.
243
244    If the repository makes use of submodules, those submodules will be cloned as well.
245
246    If the package being installed contains a `prepare` script, its `dependencies` and `devDependencies` will be installed, and the prepare script will be run, before the package is packaged and installed.
247
248    The following git environment variables are recognized by npm and will be added to the environment when running git:
249
250    * `GIT_ASKPASS`
251    * `GIT_EXEC_PATH`
252    * `GIT_PROXY_COMMAND`
253    * `GIT_SSH`
254    * `GIT_SSH_COMMAND`
255    * `GIT_SSL_CAINFO`
256    * `GIT_SSL_NO_VERIFY`
257
258    See the git man page for details.
259
260    Examples:
261
262    ```bash
263    npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
264    npm install git+ssh://git@github.com:npm/cli#pull/273
265    npm install git+ssh://git@github.com:npm/cli#semver:^5.0
266    npm install git+https://isaacs@github.com/npm/cli.git
267    npm install git://github.com/npm/cli.git#v1.0.27
268    GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
269    ```
270
271* `npm install <githubname>/<githubrepo>[#<commit-ish>]`:
272* `npm install github:<githubname>/<githubrepo>[#<commit-ish>]`:
273
274    Install the package at `https://github.com/githubname/githubrepo` by attempting to clone it using `git`.
275
276    If `#<commit-ish>` is provided, it will be used to clone exactly that commit.
277    If the commit-ish has the format `#semver:<semver>`, `<semver>` can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency.
278    If neither `#<commit-ish>` or `#semver:<semver>` is specified, then the default branch is used.
279
280    As with regular git dependencies, `dependencies` and `devDependencies` will be installed if the package has a `prepare` script before the package is done installing.
281
282    Examples:
283
284    ```bash
285    npm install mygithubuser/myproject
286    npm install github:mygithubuser/myproject
287   ```
288
289* `npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]`:
290
291    Install the package at `https://gist.github.com/gistID` by attempting to clone it using `git`.
292    The GitHub username associated with the gist is optional and will not be saved in `package.json`.
293
294    As with regular git dependencies, `dependencies` and `devDependencies` will be installed if the package has a `prepare` script before the package is done installing.
295
296    Example:
297
298    ```bash
299    npm install gist:101a11beef
300    ```
301
302* `npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]`:
303
304    Install the package at `https://bitbucket.org/bitbucketname/bitbucketrepo` by attempting to clone it using `git`.
305
306    If `#<commit-ish>` is provided, it will be used to clone exactly that commit.
307    If the commit-ish has the format `#semver:<semver>`, `<semver>` can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency.
308    If neither `#<commit-ish>` or `#semver:<semver>` is specified, then `master` is used.
309
310    As with regular git dependencies, `dependencies` and `devDependencies` will be installed if the package has a `prepare` script before the package is done installing.
311
312    Example:
313
314    ```bash
315    npm install bitbucket:mybitbucketuser/myproject
316    ```
317
318* `npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]`:
319
320    Install the package at `https://gitlab.com/gitlabname/gitlabrepo` by attempting to clone it using `git`.
321
322    If `#<commit-ish>` is provided, it will be used to clone exactly that commit.
323    If the commit-ish has the format `#semver:<semver>`, `<semver>` can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency.
324    If neither `#<commit-ish>` or `#semver:<semver>` is specified, then `master` is used.
325
326    As with regular git dependencies, `dependencies` and `devDependencies` will be installed if the package has a `prepare` script before the package is done installing.
327
328    Example:
329
330    ```bash
331    npm install gitlab:mygitlabuser/myproject
332    npm install gitlab:myusr/myproj#semver:^5.0
333    ```
334
335You may combine multiple arguments and even multiple types of arguments.
336For example:
337
338```bash
339npm install sax@">=0.1.0 <0.2.0" bench supervisor
340```
341
342The `--tag` argument will apply to all of the specified install targets.
343If a tag with the given name exists, the tagged version is preferred over newer versions.
344
345**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`.
346
347The `--dry-run` argument will report in the usual way what the install would have done without actually installing anything.
348
349The `--package-lock-only` argument will only update the `package-lock.json`, instead of checking `node_modules` and downloading dependencies.
350
351The `-f` or `--force` argument will force npm to fetch remote resources even if a local copy exists on disk.
352
353```bash
354npm install sax --force
355```
356
357### Configuration
358
359See the [`config`](/using-npm/config) help doc.
360Many of the configuration params have some effect on installation, since that's most of what npm does.
361
362These are some of the most common options related to installation.
363
364#### `save`
365
366* Default: `true` unless when using `npm update` where it defaults to `false`
367* Type: Boolean
368
369Save installed packages to a `package.json` file as dependencies.
370
371When used with the `npm rm` command, removes the dependency from
372`package.json`.
373
374Will also prevent writing to `package-lock.json` if set to `false`.
375
376
377
378#### `save-exact`
379
380* Default: false
381* Type: Boolean
382
383Dependencies saved to package.json will be configured with an exact version
384rather than using npm's default semver range operator.
385
386
387
388#### `global`
389
390* Default: false
391* Type: Boolean
392
393Operates in "global" mode, so that packages are installed into the `prefix`
394folder instead of the current working directory. See
395[folders](/configuring-npm/folders) for more on the differences in behavior.
396
397* packages are installed into the `{prefix}/lib/node_modules` folder, instead
398  of the current working directory.
399* bin files are linked to `{prefix}/bin`
400* man pages are linked to `{prefix}/share/man`
401
402
403
404#### `install-strategy`
405
406* Default: "hoisted"
407* Type: "hoisted", "nested", "shallow", or "linked"
408
409Sets the strategy for installing packages in node_modules. hoisted
410(default): Install non-duplicated in top-level, and duplicated as necessary
411within directory structure. nested: (formerly --legacy-bundling) install in
412place, no hoisting. shallow (formerly --global-style) only install direct
413deps at top-level. linked: (experimental) install in node_modules/.store,
414link in place, unhoisted.
415
416
417
418#### `legacy-bundling`
419
420* Default: false
421* Type: Boolean
422* DEPRECATED: This option has been deprecated in favor of
423  `--install-strategy=nested`
424
425Instead of hoisting package installs in `node_modules`, install packages in
426the same manner that they are depended on. This may cause very deep
427directory structures and duplicate package installs as there is no
428de-duplicating. Sets `--install-strategy=nested`.
429
430
431
432#### `global-style`
433
434* Default: false
435* Type: Boolean
436* DEPRECATED: This option has been deprecated in favor of
437  `--install-strategy=shallow`
438
439Only install direct dependencies in the top level `node_modules`, but hoist
440on deeper dependencies. Sets `--install-strategy=shallow`.
441
442
443
444#### `omit`
445
446* Default: 'dev' if the `NODE_ENV` environment variable is set to
447  'production'; otherwise, empty.
448* Type: "dev", "optional", or "peer" (can be set multiple times)
449
450Dependency types to omit from the installation tree on disk.
451
452Note that these dependencies _are_ still resolved and added to the
453`package-lock.json` or `npm-shrinkwrap.json` file. They are just not
454physically installed on disk.
455
456If a package type appears in both the `--include` and `--omit` lists, then
457it will be included.
458
459If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment
460variable will be set to `'production'` for all lifecycle scripts.
461
462
463
464#### `include`
465
466* Default:
467* Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
468
469Option that allows for defining which types of dependencies to install.
470
471This is the inverse of `--omit=<type>`.
472
473Dependency types specified in `--include` will not be omitted, regardless of
474the order in which omit/include are specified on the command-line.
475
476
477
478#### `strict-peer-deps`
479
480* Default: false
481* Type: Boolean
482
483If set to `true`, and `--legacy-peer-deps` is not set, then _any_
484conflicting `peerDependencies` will be treated as an install failure, even
485if npm could reasonably guess the appropriate resolution based on non-peer
486dependency relationships.
487
488By default, conflicting `peerDependencies` deep in the dependency graph will
489be resolved using the nearest non-peer dependency specification, even if
490doing so will result in some packages receiving a peer dependency outside
491the range set in their package's `peerDependencies` object.
492
493When such an override is performed, a warning is printed, explaining the
494conflict and the packages involved. If `--strict-peer-deps` is set, then
495this warning is treated as a failure.
496
497
498
499#### `prefer-dedupe`
500
501* Default: false
502* Type: Boolean
503
504Prefer to deduplicate packages if possible, rather than choosing a newer
505version of a dependency.
506
507
508
509#### `package-lock`
510
511* Default: true
512* Type: Boolean
513
514If set to false, then ignore `package-lock.json` files when installing. This
515will also prevent _writing_ `package-lock.json` if `save` is true.
516
517
518
519#### `package-lock-only`
520
521* Default: false
522* Type: Boolean
523
524If set to true, the current operation will only use the `package-lock.json`,
525ignoring `node_modules`.
526
527For `update` this means only the `package-lock.json` will be updated,
528instead of checking `node_modules` and downloading dependencies.
529
530For `list` this means the output will be based on the tree described by the
531`package-lock.json`, rather than the contents of `node_modules`.
532
533
534
535#### `foreground-scripts`
536
537* Default: `false` unless when using `npm pack` or `npm publish` where it
538  defaults to `true`
539* Type: Boolean
540
541Run all build scripts (ie, `preinstall`, `install`, and `postinstall`)
542scripts for installed packages in the foreground process, sharing standard
543input, output, and error with the main npm process.
544
545Note that this will generally make installs run slower, and be much noisier,
546but can be useful for debugging.
547
548
549
550#### `ignore-scripts`
551
552* Default: false
553* Type: Boolean
554
555If true, npm does not run scripts specified in package.json files.
556
557Note that commands explicitly intended to run a particular script, such as
558`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still
559run their intended script if `ignore-scripts` is set, but they will *not*
560run any pre- or post-scripts.
561
562
563
564#### `allow-git`
565
566* Default: "all"
567* Type: "all", "none", or "root"
568
569Limits the ability for npm to fetch dependencies from git references. That
570is, dependencies that point to a git repo instead of a version or semver
571range. Please note that this could leave your tree incomplete and some
572packages may not function as intended or designed.
573
574`all` allows any git dependencies to be fetched and installed. `none`
575prevents any git dependencies from being fetched and installed. `root` only
576allows git dependencies defined in your project's package.json to be fetched
577installed. Also allows git dependencies to be fetched for other commands
578like `npm view`
579
580
581
582#### `audit`
583
584* Default: true
585* Type: Boolean
586
587When "true" submit audit reports alongside the current npm command to the
588default registry and all registries configured for scopes. See the
589documentation for [`npm audit`](/commands/npm-audit) for details on what is
590submitted.
591
592
593
594#### `before`
595
596* Default: null
597* Type: null or Date
598
599If passed to `npm install`, will rebuild the npm tree such that only
600versions that were available **on or before** the given date are installed.
601If there are no versions available for the current set of dependencies, the
602command will error.
603
604If the requested version is a `dist-tag` and the given tag does not pass the
605`--before` filter, the most recent version less than or equal to that tag
606will be used. For example, `foo@latest` might install `foo@1.2` even though
607`latest` is `2.0`.
608
609This config cannot be used with: `min-release-age`
610
611#### `min-release-age`
612
613* Default: null
614* Type: null or Number
615
616If set, npm will build the npm tree such that only versions that were
617available more than the given number of days ago will be installed. If there
618are no versions available for the current set of dependencies, the command
619will error.
620
621This flag is a complement to `before`, which accepts an exact date instead
622of a relative number of days.
623
624This config cannot be used with: `before`
625
626This value is not exported to the environment for child processes.
627
628#### `bin-links`
629
630* Default: true
631* Type: Boolean
632
633Tells npm to create symlinks (or `.cmd` shims on Windows) for package
634executables.
635
636Set to false to have it not do this. This can be used to work around the
637fact that some file systems don't support symlinks, even on ostensibly Unix
638systems.
639
640
641
642#### `fund`
643
644* Default: true
645* Type: Boolean
646
647When "true" displays the message at the end of each `npm install`
648acknowledging the number of dependencies looking for funding. See [`npm
649fund`](/commands/npm-fund) for details.
650
651
652
653#### `dry-run`
654
655* Default: false
656* Type: Boolean
657
658Indicates that you don't want npm to make any changes and that it should
659only report what it would have done. This can be passed into any of the
660commands that modify your local installation, eg, `install`, `update`,
661`dedupe`, `uninstall`, as well as `pack` and `publish`.
662
663Note: This is NOT honored by other network related commands, eg `dist-tags`,
664`owner`, etc.
665
666
667
668#### `cpu`
669
670* Default: null
671* Type: null or String
672
673Override CPU architecture of native modules to install. Acceptable values
674are same as `cpu` field of package.json, which comes from `process.arch`.
675
676
677
678#### `os`
679
680* Default: null
681* Type: null or String
682
683Override OS of native modules to install. Acceptable values are same as `os`
684field of package.json, which comes from `process.platform`.
685
686
687
688#### `libc`
689
690* Default: null
691* Type: null or String
692
693Override libc of native modules to install. Acceptable values are same as
694`libc` field of package.json
695
696
697
698#### `workspace`
699
700* Default:
701* Type: String (can be set multiple times)
702
703Enable running a command in the context of the configured workspaces of the
704current project while filtering by running only the workspaces defined by
705this configuration option.
706
707Valid values for the `workspace` config are either:
708
709* Workspace names
710* Path to a workspace directory
711* Path to a parent workspace directory (will result in selecting all
712  workspaces within that folder)
713
714When set for the `npm init` command, this may be set to the folder of a
715workspace which does not yet exist, to create the folder and set it up as a
716brand new workspace within the project.
717
718This value is not exported to the environment for child processes.
719
720#### `workspaces`
721
722* Default: null
723* Type: null or Boolean
724
725Set to true to run the command in the context of **all** configured
726workspaces.
727
728Explicitly setting this to false will cause commands like `install` to
729ignore workspaces altogether. When not set explicitly:
730
731- Commands that operate on the `node_modules` tree (install, update, etc.)
732will link workspaces into the `node_modules` folder. - Commands that do
733other things (test, exec, publish, etc.) will operate on the root project,
734_unless_ one or more workspaces are specified in the `workspace` config.
735
736This value is not exported to the environment for child processes.
737
738#### `include-workspace-root`
739
740* Default: false
741* Type: Boolean
742
743Include the workspace root when workspaces are enabled for a command.
744
745When false, specifying individual workspaces via the `workspace` config, or
746all workspaces via the `workspaces` flag, will cause npm to operate only on
747the specified workspaces, and not on the root project.
748
749This value is not exported to the environment for child processes.
750
751#### `install-links`
752
753* Default: false
754* Type: Boolean
755
756When set file: protocol dependencies will be packed and installed as regular
757dependencies instead of creating a symlink. This option has no effect on
758workspaces.
759
760
761
762### Algorithm
763
764Given a `package{dep}` structure: `A{B,C}, B{C}, C{D}`, the npm install algorithm produces:
765
766```bash
767A
768+-- B
769+-- C
770+-- D
771```
772
773That is, the dependency from B to C is satisfied by the fact that A already caused C to be installed at a higher level.
774D is still installed at the top level because nothing conflicts with it.
775
776For `A{B,C}, B{C,D@1}, C{D@2}`, this algorithm produces:
777
778```bash
779A
780+-- B
781+-- C
782   `-- D@2
783+-- D@1
784```
785
786Because B's D@1 will be installed in the top-level, C now has to install D@2 privately for itself.
787This algorithm is deterministic, but different trees may be produced if two dependencies are requested for installation in a different order.
788
789See [folders](/configuring-npm/folders) for a more detailed description of the specific folder structures that npm creates.
790
791### See Also
792
793* [npm folders](/configuring-npm/folders)
794* [npm update](/commands/npm-update)
795* [npm audit](/commands/npm-audit)
796* [npm fund](/commands/npm-fund)
797* [npm link](/commands/npm-link)
798* [npm rebuild](/commands/npm-rebuild)
799* [npm scripts](/using-npm/scripts)
800* [npm config](/commands/npm-config)
801* [npmrc](/configuring-npm/npmrc)
802* [npm registry](/using-npm/registry)
803* [npm dist-tag](/commands/npm-dist-tag)
804* [npm uninstall](/commands/npm-uninstall)
805* [npm shrinkwrap](/commands/npm-shrinkwrap)
806* [package.json](/configuring-npm/package-json)
807* [workspaces](/using-npm/workspaces)
808 
codekingpro/portable-devtools · Team Ai