.TH "NPM\-LINK" "1" "November 2022" "9.1.1" .SH "NAME" \fBnpm-link\fR .SH Synopsis .SH Description .P This is handy for installing your own stuff, so that you can work on it and .br test iteratively without having to continually rebuild\. .P Package linking is a two\-step process\. .P First, \fBnpm link\fP in a package folder with no arguments will create a .br symlink in the global folder \fB{prefix}/lib/node_modules/\fP that .br links to the package where the \fBnpm link\fP command was executed\. It will .br also link any bins in the package to \fB{prefix}/bin/{name}\fP\|\. Note that .br \fBnpm link\fP uses the global prefix (see \fBnpm prefix \-g\fP for its value)\. .P Next, in some other location, \fBnpm link package\-name\fP will create a .br symbolic link from globally\-installed \fBpackage\-name\fP to \fBnode_modules/\fP of .br the current folder\. .P Note that \fBpackage\-name\fP is taken from \fBpackage\.json\fP, \fInot\fR from the .br directory name\. .P The package name can be optionally prefixed with a scope\. See .br \fBscope\fP\|\. The scope must be preceded by an @\-symbol and .br followed by a slash\. .P When creating tarballs for \fBnpm publish\fP, the linked packages are .br "snapshotted" to their current state by resolving the symbolic links, if .br they are included in \fBbundleDependencies\fP\|\. .P For example: .RS 2 .nf cd ~/projects/node\-redis # go into the package directory npm link # creates global link cd ~/projects/node\-bloggy # go into some other package directory\. npm link redis # link\-install the package .fi .RE .P Now, any changes to \fB~/projects/node\-redis\fP will be reflected in .br \fB~/projects/node\-bloggy/node_modules/node\-redis/\fP\|\. Note that the link .br should be to the package name, not the directory name for that package\. .P You may also shortcut the two steps in one\. For example, to do the .br above use\-case in a shorter way: .RS 2 .nf cd ~/projects/node\-bloggy # go into the dir of your main project npm link \.\./node\-redis # link the dir of your dependency .fi .RE .P The second line is the equivalent of doing: .RS 2 .nf (cd \.\./node\-redis; npm link) npm link redis .fi .RE .P That is, it first creates a global link, and then links the global .br installation target into your project's \fBnode_modules\fP folder\. .P Note that in this case, you are referring to the directory name, .br \fBnode\-redis\fP, rather than the package name \fBredis\fP\|\. .P If your linked package is scoped (see \fBscope\fP) your .br link command must include that scope, e\.g\. .RS 2 .nf npm link @myorg/privatepackage .fi .RE .SH Caveat .P Note that package dependencies linked in this way are \fInot\fR saved to .br \fBpackage\.json\fP by default, on the assumption that the intention is to have .br a link stand in for a regular non\-link dependency\. Otherwise, for example, .br if you depend on \fBredis@^3\.0\.1\fP, and ran \fBnpm link redis\fP, it would replace .br the \fB^3\.0\.1\fP dependency with \fBfile:\.\./path/to/node\-redis\fP, which you .br probably don't want! Additionally, other users or developers on your .br project would run into issues if they do not have their folders set up .br exactly the same as yours\. .P If you are adding a \fInew\fR dependency as a link, you should add it to the .br relevant metadata by running \fBnpm install \-\-package\-lock\-only\fP\|\. .P If you \fIwant\fR to save the \fBfile:\fP reference in your \fBpackage\.json\fP and .br \fBpackage\-lock\.json\fP files, you can use \fBnpm link \-\-save\fP to do so\. .SH Workspace Usage .P \fBnpm link \-\-workspace \fP will link the relevant package as a .br dependency of the specified workspace(s)\. Note that It may actually be .br linked into the parent project's \fBnode_modules\fP folder, if there are no .br conflicting dependencies\. .P \fBnpm link \-\-workspace \fP will create a global link to the specified .br workspace(s)\. .SH Configuration .SH See Also .RS 1 .IP \(bu 2 package spec .IP \(bu 2 npm developers .IP \(bu 2 package\.json .IP \(bu 2 npm install .IP \(bu 2 npm folders .IP \(bu 2 npm config .IP \(bu 2 npmrc .RE