1 ---
2 title: npm-link
3 section: 1
4 description: Symlink a package folder
5 github_repo: npm/cli
6 github_branch: release/v8
7 github_path: docs/lib/content/commands/npm-link.md
8 redirect_from:
9 - /cli-documentation/v8/cli-commands/link
10 - /cli-documentation/v8/cli-commands/npm-link
11 - /cli-documentation/v8/commands/link
12 - /cli-documentation/v8/commands/npm-link
13 - /cli-documentation/v8/link
14 - /cli-documentation/v8/npm-link
15 - /cli/v8/cli-commands/link
16 - /cli/v8/cli-commands/npm-link
17 - /cli/v8/commands/link
18 - /cli/v8/link
19 - /cli/v8/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/v8/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/v8/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/v8/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 #### `global-style`
127
128 - Default: false
129 - Type: Boolean
130
131 Causes npm to install the package into your local `node_modules` folder with the same layout it uses with the global `node_modules` folder. Only your direct dependencies will show in `node_modules` and everything they depend on will be flattened in their `node_modules` folders. This obviously will eliminate some deduping. If used with `legacy-bundling`, `legacy-bundling` will be preferred.
132
133 #### `legacy-bundling`
134
135 - Default: false
136 - Type: Boolean
137
138 Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with `global-style` this option will be preferred.
139
140 #### `strict-peer-deps`
141
142 - Default: false
143 - Type: Boolean
144
145 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.
146
147 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.
148
149 When such and 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.
150
151 #### `package-lock`
152
153 - Default: true
154 - Type: Boolean
155
156 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
157
158 This configuration does not affect `npm ci`.
159
160 #### `omit`
161
162 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
163 - Type: "dev", "optional", or "peer" (can be set multiple times)
164
165 Dependency types to omit from the installation tree on disk.
166
167 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.
168
169 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
170
171 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
172
173 #### `ignore-scripts`
174
175 - Default: false
176 - Type: Boolean
177
178 If true, npm does not run scripts specified in package.json files.
179
180 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.
181
182 #### `audit`
183
184 - Default: true
185 - Type: Boolean
186
187 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/v8/commands/npm-audit) for details on what is submitted.
188
189 #### `bin-links`
190
191 - Default: true
192 - Type: Boolean
193
194 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
195
196 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.
197
198 #### `fund`
199
200 - Default: true
201 - Type: Boolean
202
203 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v8/commands/npm-fund) for details.
204
205 #### `dry-run`
206
207 - Default: false
208 - Type: Boolean
209
210 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`.
211
212 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
213
214 #### `workspace`
215
216 - Default:
217 - Type: String (can be set multiple times)
218
219 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.
220
221 Valid values for the `workspace` config are either:
222
223 - Workspace names
224 - Path to a workspace directory
225 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
226
227 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.
228
229 This value is not exported to the environment for child processes.
230
231 #### `workspaces`
232
233 - Default: null
234 - Type: null or Boolean
235
236 Set to true to run the command in the context of **all** configured workspaces.
237
238 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
239
240 - 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.
241
242 This value is not exported to the environment for child processes.
243
244 #### `include-workspace-root`
245
246 - Default: false
247 - Type: Boolean
248
249 Include the workspace root when workspaces are enabled for a command.
250
251 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.
252
253 This value is not exported to the environment for child processes.
254
255 #### `install-links`
256
257 - Default: false
258 - Type: Boolean
259
260 When set file: protocol dependencies that exist outside of the project root will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
261
262 ### See Also
263
264 - [package spec](/cli/v8/using-npm/package-spec)
265 - [npm developers](/cli/v8/using-npm/developers)
266 - [package.json](/cli/v8/configuring-npm/package-json)
267 - [npm install](/cli/v8/commands/npm-install)
268 - [npm folders](/cli/v8/configuring-npm/folders)
269 - [npm config](/cli/v8/commands/npm-config)
270 - [npmrc](/cli/v8/configuring-npm/npmrc)