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