nodejs/deps/npm/man/man1/npm-link.1

102 lines
2.8 KiB
Groff
Raw Normal View History

.TH "NPM\-LINK" "1" "October 2020" "" ""
.SH "NAME"
\fBnpm-link\fR \- Symlink a package folder
.SS Synopsis
2014-09-24 14:41:07 -07:00
.P
.RS 2
2014-11-04 15:08:12 -08:00
.nf
npm link (in package dir)
npm link [<@scope>/]<pkg>[@<version>]
alias: npm ln
2014-11-04 15:08:12 -08:00
.fi
2014-09-24 14:41:07 -07:00
.RE
.SS Description
2014-09-24 14:41:07 -07:00
.P
Package linking is a two\-step process\.
.P
First, \fBnpm link\fP in a package folder will create a symlink in the global folder
\fB{prefix}/lib/node_modules/<package>\fP that links to the package where the \fBnpm
link\fP command was executed\. It will also link any bins in the package to \fB{prefix}/bin/{name}\fP\|\.
Note that \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
symbolic link from globally\-installed \fBpackage\-name\fP to \fBnode_modules/\fP
of the current folder\.
.P
Note that \fBpackage\-name\fP is taken from \fBpackage\.json\fP,
2013-05-14 14:37:59 -07:00
not from directory name\.
2014-09-24 14:41:07 -07:00
.P
The package name can be optionally prefixed with a scope\. See npm help \fBscope\fP\|\.
The scope must be preceded by an @\-symbol and followed by a slash\.
2013-05-14 14:37:59 -07:00
.P
When creating tarballs for \fBnpm publish\fP, the linked packages are
"snapshotted" to their current state by resolving the symbolic links\.
.P
2014-09-24 14:41:07 -07:00
This is handy for installing your own stuff, so that you can work on it and
test it iteratively without having to continually rebuild\.
.P
For example:
2014-09-24 14:41:07 -07:00
.P
.RS 2
2014-11-04 15:08:12 -08:00
.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
2014-11-04 15:08:12 -08:00
.fi
2014-09-24 14:41:07 -07:00
.RE
.P
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\.
.P
You may also shortcut the two steps in one\. For example, to do the
above use\-case in a shorter way:
2014-09-24 14:41:07 -07:00
.P
.RS 2
2014-11-04 15:08:12 -08:00
.nf
cd ~/projects/node\-bloggy # go into the dir of your main project
npm link \.\./node\-redis # link the dir of your dependency
2014-11-04 15:08:12 -08:00
.fi
2014-09-24 14:41:07 -07:00
.RE
.P
The second line is the equivalent of doing:
2014-09-24 14:41:07 -07:00
.P
.RS 2
2014-11-04 15:08:12 -08:00
.nf
(cd \.\./node\-redis; npm link)
npm link redis
2014-11-04 15:08:12 -08:00
.fi
2014-09-24 14:41:07 -07:00
.RE
.P
That is, it first creates a global link, and then links the global
installation target into your project's \fBnode_modules\fP folder\.
2014-09-24 14:41:07 -07:00
.P
Note that in this case, you are referring to the directory name, \fBnode\-redis\fP,
rather than the package name \fBredis\fP\|\.
.P
If your linked package is scoped (see npm help \fBscope\fP) your link command must include that scope, e\.g\.
2014-09-24 14:41:07 -07:00
.P
.RS 2
2014-11-04 15:08:12 -08:00
.nf
2014-09-24 14:41:07 -07:00
npm link @myorg/privatepackage
2014-11-04 15:08:12 -08:00
.fi
2014-09-24 14:41:07 -07:00
.RE
.SS See Also
2014-09-24 14:41:07 -07:00
.RS 0
.IP \(bu 2
npm help developers
2014-09-24 14:41:07 -07:00
.IP \(bu 2
npm help package\.json
2014-09-24 14:41:07 -07:00
.IP \(bu 2
npm help npm\- nstall
2014-09-24 14:41:07 -07:00
.IP \(bu 2
npm help folders
2014-09-24 14:41:07 -07:00
.IP \(bu 2
npm help config
2014-09-24 14:41:07 -07:00
.IP \(bu 2
npm help npmrc
2014-09-24 14:41:07 -07:00
.RE