1 ---
2 title: npm-link
3 section: 1
4 description: Symlink a package folder
5 github_repo: npm/cli
6 github_branch: release/v9
7 github_path: docs/lib/content/commands/npm-link.md
8 redirect_from:
9 - /cli-documentation/v9/cli-commands/link
10 - /cli-documentation/v9/cli-commands/npm-link
11 - /cli-documentation/v9/commands/link
12 - /cli-documentation/v9/commands/npm-link
13 - /cli-documentation/v9/link
14 - /cli-documentation/v9/npm-link
15 - /cli/v9/cli-commands/link
16 - /cli/v9/cli-commands/npm-link
17 - /cli/v9/commands/link
18 - /cli/v9/link
19 - /cli/v9/npm-link
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm link [<package-spec>]
26
27 alias: ln
28 ```
29
30 ### Description
31
32 This is handy for installing your own stuff, so that you can work on it and test iteratively without having to continually rebuild.
33
34 Package linking is a two-step process.
35
36 First, `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. It will also link any bins in the package to `{prefix}/bin/{name}`. Note that `npm link` uses the global prefix (see `npm prefix -g` for its value).
37
38 Next, 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.
39
40 Note that `package-name` is taken from `package.json`, _not_ from the directory name.
41
42 The package name can be optionally prefixed with a scope. See [`scope`](/cli/v9/using-npm/scope). The scope must be preceded by an @-symbol and followed by a slash.
43
44 When 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`.
45
46 For example:
47
48 ```bash
49 cd ~/projects/node-redis # go into the package directory
50 npm link # creates global link
51 cd ~/projects/node-bloggy # go into some other package directory.
52 npm link redis # link-install the package
53 ```
54
55 Now, any changes to `~/projects/node-redis` will be reflected in `~/projects/node-bloggy/node_modules/node-redis/`. Note that the link should be to the package name, not the directory name for that package.
56
57 You may also shortcut the two steps in one. For example, to do the above use-case in a shorter way:
58
59 ```bash
60 cd ~/projects/node-bloggy # go into the dir of your main project
61 npm link ../node-redis # link the dir of your dependency
62 ```
63
64 The second line is the equivalent of doing:
65
66 ```bash
67 (cd ../node-redis; npm link)
68 npm link redis
69 ```
70
71 That is, it first creates a global link, and then links the global installation target into your project's `node_modules` folder.
72
73 Note that in this case, you are referring to the directory name, `node-redis`, rather than the package name `redis`.
74
75 If your linked package is scoped (see [`scope`](/cli/v9/using-npm/scope)) your link command must include that scope, e.g.
76
77 ```bash
78 npm link @myorg/privatepackage
79 ```
80
81 ### Caveat
82
83 Note 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. Otherwise, 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.
84
85 If 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`.
86
87 If 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.
88
89 ### Workspace Usage
90
91 `npm link <pkg> --workspace <name>` 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 `node_modules` folder, if there are no conflicting dependencies.
92
93 `npm link --workspace <name>` will create a global link to the specified workspace(s).
94
95 ### Configuration
96
97 #### `save`
98
99 - Default: `true` unless when using `npm update` where it defaults to `false`
100 - Type: Boolean
101
102 Save installed packages to a `package.json` file as dependencies.
103
104 When used with the `npm rm` command, removes the dependency from `package.json`.
105
106 Will also prevent writing to `package-lock.json` if set to `false`.
107
108 #### `save-exact`
109
110 - Default: false
111 - Type: Boolean
112
113 Dependencies saved to package.json will be configured with an exact version rather than using npm's default semver range operator.
114
115 #### `global`
116
117 - Default: false
118 - Type: Boolean
119
120 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v9/configuring-npm/folders) for more on the differences in behavior.
121
122 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
123 - bin files are linked to `{prefix}/bin`
124 - man pages are linked to `{prefix}/share/man`
125
126 #### `install-strategy`
127
128 - Default: "hoisted"
129 - Type: "hoisted", "nested", "shallow", or "linked"
130
131 Sets 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.
132
133 #### `legacy-bundling`
134
135 - Default: false
136 - Type: Boolean
137 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=nested`
138
139 Instead of hoisting package installs in `node_modules`, 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 `--install-strategy=nested`.
140
141 #### `global-style`
142
143 - Default: false
144 - Type: Boolean
145 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=shallow`
146
147 Only install direct dependencies in the top level `node_modules`, but hoist on deeper dependencies. Sets `--install-strategy=shallow`.
148
149 #### `strict-peer-deps`
150
151 - Default: false
152 - Type: Boolean
153
154 If set to `true`, and `--legacy-peer-deps` is not set, then _any_ conflicting `peerDependencies` will be treated as an install failure, even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships.
155
156 By default, conflicting `peerDependencies` 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 `peerDependencies` object.
157
158 When such an override is performed, a warning is printed, explaining the conflict and the packages involved. If `--strict-peer-deps` is set, then this warning is treated as a failure.
159
160 #### `package-lock`
161
162 - Default: true
163 - Type: Boolean
164
165 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
166
167 #### `omit`
168
169 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
170 - Type: "dev", "optional", or "peer" (can be set multiple times)
171
172 Dependency types to omit from the installation tree on disk.
173
174 Note that these dependencies _are_ still resolved and added to the `package-lock.json` or `npm-shrinkwrap.json` file. They are just not physically installed on disk.
175
176 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
177
178 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
179
180 #### `ignore-scripts`
181
182 - Default: false
183 - Type: Boolean
184
185 If true, npm does not run scripts specified in package.json files.
186
187 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
188
189 #### `audit`
190
191 - Default: true
192 - Type: Boolean
193
194 When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. See the documentation for [`npm audit`](/cli/v9/commands/npm-audit) for details on what is submitted.
195
196 #### `bin-links`
197
198 - Default: true
199 - Type: Boolean
200
201 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
202
203 Set 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.
204
205 #### `fund`
206
207 - Default: true
208 - Type: Boolean
209
210 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v9/commands/npm-fund) for details.
211
212 #### `dry-run`
213
214 - Default: false
215 - Type: Boolean
216
217 Indicates 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, `install`, `update`, `dedupe`, `uninstall`, as well as `pack` and `publish`.
218
219 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
220
221 #### `workspace`
222
223 - Default:
224 - Type: String (can be set multiple times)
225
226 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.
227
228 Valid values for the `workspace` config are either:
229
230 - Workspace names
231 - Path to a workspace directory
232 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
233
234 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.
235
236 This value is not exported to the environment for child processes.
237
238 #### `workspaces`
239
240 - Default: null
241 - Type: null or Boolean
242
243 Set to true to run the command in the context of **all** configured workspaces.
244
245 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
246
247 - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config.
248
249 This value is not exported to the environment for child processes.
250
251 #### `include-workspace-root`
252
253 - Default: false
254 - Type: Boolean
255
256 Include the workspace root when workspaces are enabled for a command.
257
258 When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project.
259
260 This value is not exported to the environment for child processes.
261
262 #### `install-links`
263
264 - Default: false
265 - Type: Boolean
266
267 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
268
269 ### See Also
270
271 - [package spec](/cli/v9/using-npm/package-spec)
272 - [npm developers](/cli/v9/using-npm/developers)
273 - [package.json](/cli/v9/configuring-npm/package-json)
274 - [npm install](/cli/v9/commands/npm-install)
275 - [npm folders](/cli/v9/configuring-npm/folders)
276 - [npm config](/cli/v9/commands/npm-config)
277 - [npmrc](/cli/v9/configuring-npm/npmrc)