Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
npm-link.md394 linesDownload Raw Back to commands
1---
2title: npm-link
3section: 1
4description: Symlink a package folder
5---
6
7### Synopsis
8
9```bash
10npm link [<package-spec>]
11
12alias: ln
13```
14
15### Description
16
17This is handy for installing your own stuff, so that you can work on it and test iteratively without having to continually rebuild.
18
19Package linking is a two-step process.
20
21First, `npm link` in a package folder with no arguments will create a symlink in the global folder `{prefix}/lib/node_modules/<package>` that links to the package where the `npm link` command was executed.
22It will also link any bins in the package to `{prefix}/bin/{name}`.
23Note that `npm link` uses the global prefix (see `npm prefix -g` for its value).
24
25Next, in some other location, `npm link package-name` will create a symbolic link from globally-installed `package-name` to `node_modules/` of the current folder.
26
27Note that `package-name` is taken from `package.json`, _not_ from the directory name.
28
29The package name can be optionally prefixed with a scope.
30See [`scope`](/using-npm/scope).
31The scope must be preceded by an @-symbol and followed by a slash.
32
33When creating tarballs for `npm publish`, the linked packages are "snapshotted" to their current state by resolving the symbolic links, if they are included in `bundleDependencies`.
34
35For example:
36
37```bash
38cd ~/projects/node-redis    # go into the package directory
39npm link                    # creates global link
40cd ~/projects/node-bloggy   # go into some other package directory.
41npm link redis              # link-install the package
42```
43
44Now, any changes to `~/projects/node-redis` will be reflected in
45`~/projects/node-bloggy/node_modules/node-redis/`.
46Note that the link should be to the package name, not the directory name for that package.
47
48You may also shortcut the two steps in one.
49For example, to do the above use-case in a shorter way:
50
51```bash
52cd ~/projects/node-bloggy  # go into the dir of your main project
53npm link ../node-redis     # link the dir of your dependency
54```
55
56The second line is the equivalent of doing:
57
58```bash
59(cd ../node-redis; npm link)
60npm link redis
61```
62
63That is, it first creates a global link, and then links the global installation target into your project's `node_modules` folder.
64
65Note that in this case, you are referring to the directory name,
66`node-redis`, rather than the package name `redis`.
67
68If your linked package is scoped (see [`scope`](/using-npm/scope)) your link command must include that scope, e.g.
69
70```bash
71npm link @myorg/privatepackage
72```
73
74### Caveat
75
76Note that package dependencies linked in this way are _not_ saved to `package.json` by default, on the assumption that the intention is to have a link stand in for a regular non-link dependency.
77Otherwise, for example, if you depend on `redis@^3.0.1`, and ran `npm link redis`, it would replace the `^3.0.1` dependency with `file:../path/to/node-redis`, which you probably don't want!  Additionally, other users or developers on your project would run into issues if they do not have their folders set up exactly the same as yours.
78
79If you are adding a _new_ dependency as a link, you should add it to the relevant metadata by running `npm install <dep> --package-lock-only`.
80
81If you _want_ to save the `file:` reference in your `package.json` and `package-lock.json` files, you can use `npm link <dep> --save` to do so.
82
83### Workspace Usage
84
85`npm link <pkg> --workspace <name>` will link the relevant package as a dependency of the specified workspace(s).
86Note that It may actually be linked into the parent project's `node_modules` folder, if there are no conflicting dependencies.
87
88`npm link --workspace <name>` will create a global link to the specified workspace(s).
89
90### Configuration
91
92#### `save`
93
94* Default: `true` unless when using `npm update` where it defaults to `false`
95* Type: Boolean
96
97Save installed packages to a `package.json` file as dependencies.
98
99When used with the `npm rm` command, removes the dependency from
100`package.json`.
101
102Will also prevent writing to `package-lock.json` if set to `false`.
103
104
105
106#### `save-exact`
107
108* Default: false
109* Type: Boolean
110
111Dependencies saved to package.json will be configured with an exact version
112rather than using npm's default semver range operator.
113
114
115
116#### `global`
117
118* Default: false
119* Type: Boolean
120
121Operates in "global" mode, so that packages are installed into the `prefix`
122folder instead of the current working directory. See
123[folders](/configuring-npm/folders) for more on the differences in behavior.
124
125* packages are installed into the `{prefix}/lib/node_modules` folder, instead
126  of the current working directory.
127* bin files are linked to `{prefix}/bin`
128* man pages are linked to `{prefix}/share/man`
129
130
131
132#### `install-strategy`
133
134* Default: "hoisted"
135* Type: "hoisted", "nested", "shallow", or "linked"
136
137Sets the strategy for installing packages in node_modules. hoisted
138(default): Install non-duplicated in top-level, and duplicated as necessary
139within directory structure. nested: (formerly --legacy-bundling) install in
140place, no hoisting. shallow (formerly --global-style) only install direct
141deps at top-level. linked: (experimental) install in node_modules/.store,
142link in place, unhoisted.
143
144
145
146#### `legacy-bundling`
147
148* Default: false
149* Type: Boolean
150* DEPRECATED: This option has been deprecated in favor of
151  `--install-strategy=nested`
152
153Instead of hoisting package installs in `node_modules`, install packages in
154the same manner that they are depended on. This may cause very deep
155directory structures and duplicate package installs as there is no
156de-duplicating. Sets `--install-strategy=nested`.
157
158
159
160#### `global-style`
161
162* Default: false
163* Type: Boolean
164* DEPRECATED: This option has been deprecated in favor of
165  `--install-strategy=shallow`
166
167Only install direct dependencies in the top level `node_modules`, but hoist
168on deeper dependencies. Sets `--install-strategy=shallow`.
169
170
171
172#### `strict-peer-deps`
173
174* Default: false
175* Type: Boolean
176
177If set to `true`, and `--legacy-peer-deps` is not set, then _any_
178conflicting `peerDependencies` will be treated as an install failure, even
179if npm could reasonably guess the appropriate resolution based on non-peer
180dependency relationships.
181
182By default, conflicting `peerDependencies` deep in the dependency graph will
183be resolved using the nearest non-peer dependency specification, even if
184doing so will result in some packages receiving a peer dependency outside
185the range set in their package's `peerDependencies` object.
186
187When such an override is performed, a warning is printed, explaining the
188conflict and the packages involved. If `--strict-peer-deps` is set, then
189this warning is treated as a failure.
190
191
192
193#### `package-lock`
194
195* Default: true
196* Type: Boolean
197
198If set to false, then ignore `package-lock.json` files when installing. This
199will also prevent _writing_ `package-lock.json` if `save` is true.
200
201
202
203#### `omit`
204
205* Default: 'dev' if the `NODE_ENV` environment variable is set to
206  'production'; otherwise, empty.
207* Type: "dev", "optional", or "peer" (can be set multiple times)
208
209Dependency types to omit from the installation tree on disk.
210
211Note that these dependencies _are_ still resolved and added to the
212`package-lock.json` or `npm-shrinkwrap.json` file. They are just not
213physically installed on disk.
214
215If a package type appears in both the `--include` and `--omit` lists, then
216it will be included.
217
218If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment
219variable will be set to `'production'` for all lifecycle scripts.
220
221
222
223#### `include`
224
225* Default:
226* Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
227
228Option that allows for defining which types of dependencies to install.
229
230This is the inverse of `--omit=<type>`.
231
232Dependency types specified in `--include` will not be omitted, regardless of
233the order in which omit/include are specified on the command-line.
234
235
236
237#### `ignore-scripts`
238
239* Default: false
240* Type: Boolean
241
242If true, npm does not run scripts specified in package.json files.
243
244Note that commands explicitly intended to run a particular script, such as
245`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still
246run their intended script if `ignore-scripts` is set, but they will *not*
247run any pre- or post-scripts.
248
249
250
251#### `allow-git`
252
253* Default: "all"
254* Type: "all", "none", or "root"
255
256Limits the ability for npm to fetch dependencies from git references. That
257is, dependencies that point to a git repo instead of a version or semver
258range. Please note that this could leave your tree incomplete and some
259packages may not function as intended or designed.
260
261`all` allows any git dependencies to be fetched and installed. `none`
262prevents any git dependencies from being fetched and installed. `root` only
263allows git dependencies defined in your project's package.json to be fetched
264installed. Also allows git dependencies to be fetched for other commands
265like `npm view`
266
267
268
269#### `audit`
270
271* Default: true
272* Type: Boolean
273
274When "true" submit audit reports alongside the current npm command to the
275default registry and all registries configured for scopes. See the
276documentation for [`npm audit`](/commands/npm-audit) for details on what is
277submitted.
278
279
280
281#### `bin-links`
282
283* Default: true
284* Type: Boolean
285
286Tells npm to create symlinks (or `.cmd` shims on Windows) for package
287executables.
288
289Set to false to have it not do this. This can be used to work around the
290fact that some file systems don't support symlinks, even on ostensibly Unix
291systems.
292
293
294
295#### `fund`
296
297* Default: true
298* Type: Boolean
299
300When "true" displays the message at the end of each `npm install`
301acknowledging the number of dependencies looking for funding. See [`npm
302fund`](/commands/npm-fund) for details.
303
304
305
306#### `dry-run`
307
308* Default: false
309* Type: Boolean
310
311Indicates that you don't want npm to make any changes and that it should
312only report what it would have done. This can be passed into any of the
313commands that modify your local installation, eg, `install`, `update`,
314`dedupe`, `uninstall`, as well as `pack` and `publish`.
315
316Note: This is NOT honored by other network related commands, eg `dist-tags`,
317`owner`, etc.
318
319
320
321#### `workspace`
322
323* Default:
324* Type: String (can be set multiple times)
325
326Enable running a command in the context of the configured workspaces of the
327current project while filtering by running only the workspaces defined by
328this configuration option.
329
330Valid values for the `workspace` config are either:
331
332* Workspace names
333* Path to a workspace directory
334* Path to a parent workspace directory (will result in selecting all
335  workspaces within that folder)
336
337When set for the `npm init` command, this may be set to the folder of a
338workspace which does not yet exist, to create the folder and set it up as a
339brand new workspace within the project.
340
341This value is not exported to the environment for child processes.
342
343#### `workspaces`
344
345* Default: null
346* Type: null or Boolean
347
348Set to true to run the command in the context of **all** configured
349workspaces.
350
351Explicitly setting this to false will cause commands like `install` to
352ignore workspaces altogether. When not set explicitly:
353
354- Commands that operate on the `node_modules` tree (install, update, etc.)
355will link workspaces into the `node_modules` folder. - Commands that do
356other things (test, exec, publish, etc.) will operate on the root project,
357_unless_ one or more workspaces are specified in the `workspace` config.
358
359This value is not exported to the environment for child processes.
360
361#### `include-workspace-root`
362
363* Default: false
364* Type: Boolean
365
366Include the workspace root when workspaces are enabled for a command.
367
368When false, specifying individual workspaces via the `workspace` config, or
369all workspaces via the `workspaces` flag, will cause npm to operate only on
370the specified workspaces, and not on the root project.
371
372This value is not exported to the environment for child processes.
373
374#### `install-links`
375
376* Default: false
377* Type: Boolean
378
379When set file: protocol dependencies will be packed and installed as regular
380dependencies instead of creating a symlink. This option has no effect on
381workspaces.
382
383
384
385### See Also
386
387* [package spec](/using-npm/package-spec)
388* [npm developers](/using-npm/developers)
389* [package.json](/configuring-npm/package-json)
390* [npm install](/commands/npm-install)
391* [npm folders](/configuring-npm/folders)
392* [npm config](/commands/npm-config)
393* [npmrc](/configuring-npm/npmrc)
394 
codekingpro/portable-devtools · Team Ai