2021-05-10 17:31:02 -04:00
|
|
|
.TH "NPM\-LINK" "1" "May 2021" "" ""
|
2011-11-26 09:21:03 -08:00
|
|
|
.SH "NAME"
|
2019-11-18 21:01:39 +02:00
|
|
|
\fBnpm-link\fR \- Symlink a package folder
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Synopsis
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
2014-11-04 15:08:12 -08:00
|
|
|
.nf
|
2015-10-09 23:13:57 -07:00
|
|
|
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
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS Description
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
This is handy for installing your own stuff, so that you can work on it and
|
|
|
|
test iteratively without having to continually rebuild\.
|
|
|
|
.P
|
2011-11-26 09:21:03 -08:00
|
|
|
Package linking is a two\-step process\.
|
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
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)\.
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
Next, in some other location, \fBnpm link package\-name\fP will create a
|
2020-12-11 18:54:56 -05:00
|
|
|
symbolic link from globally\-installed \fBpackage\-name\fP to \fBnode_modules/\fP of
|
|
|
|
the current folder\.
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
Note that \fBpackage\-name\fP is taken from \fBpackage\.json\fP, \fInot\fR from the
|
|
|
|
directory name\.
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
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
|
2015-07-24 15:09:52 -07:00
|
|
|
When creating tarballs for \fBnpm publish\fP, the linked packages are
|
2020-12-11 18:54:56 -05:00
|
|
|
"snapshotted" to their current state by resolving the symbolic links, if
|
|
|
|
they are included in \fBbundleDependencies\fP\|\.
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
|
|
|
For example:
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
|
|
|
.RS 2
|
2014-11-04 15:08:12 -08:00
|
|
|
.nf
|
2020-12-11 18:54:56 -05:00
|
|
|
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
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
Now, any changes to \fB~/projects/node\-redis\fP will be reflected in
|
|
|
|
\fB~/projects/node\-bloggy/node_modules/node\-redis/\fP\|\. Note that the link
|
|
|
|
should be to the package name, not the directory name for that package\.
|
2011-11-26 09:21:03 -08:00
|
|
|
.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
|
2011-11-26 09:21:03 -08:00
|
|
|
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
|
2011-11-26 09:21:03 -08:00
|
|
|
.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
|
2011-11-26 09:21:03 -08:00
|
|
|
(cd \.\./node\-redis; npm link)
|
2018-07-18 13:55:52 -07:00
|
|
|
npm link redis
|
2014-11-04 15:08:12 -08:00
|
|
|
.fi
|
2014-09-24 14:41:07 -07:00
|
|
|
.RE
|
2011-11-26 09:21:03 -08:00
|
|
|
.P
|
|
|
|
That is, it first creates a global link, and then links the global
|
2015-07-24 15:09:52 -07:00
|
|
|
installation target into your project's \fBnode_modules\fP folder\.
|
2014-09-24 14:41:07 -07:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
Note that in this case, you are referring to the directory name,
|
|
|
|
\fBnode\-redis\fP, rather than the package name \fBredis\fP\|\.
|
2018-07-18 13:55:52 -07:00
|
|
|
.P
|
2020-12-11 18:54:56 -05:00
|
|
|
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
|
2020-12-11 18:54:56 -05:00
|
|
|
.SS Caveat
|
|
|
|
.P
|
|
|
|
Note that package dependencies linked in this way are \fInot\fR saved to
|
|
|
|
\fBpackage\.json\fP 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\fP, and ran \fBnpm link redis\fP, it would replace
|
|
|
|
the \fB^3\.0\.1\fP dependency with \fBfile:\.\./path/to/node\-redis\fP, 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\.
|
|
|
|
.P
|
|
|
|
If 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\fP\|\.
|
|
|
|
.P
|
|
|
|
If you \fIwant\fR to save the \fBfile:\fP reference in your \fBpackage\.json\fP and
|
|
|
|
\fBpackage\-lock\.json\fP files, you can use \fBnpm link <dep> \-\-save\fP to do so\.
|
2019-11-05 14:55:08 -05:00
|
|
|
.SS See Also
|
2014-09-24 14:41:07 -07:00
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
2019-11-05 14:55:08 -05:00
|
|
|
npm help developers
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help package\.json
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2020-11-01 07:54:36 +01:00
|
|
|
npm help install
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-05 14:55:08 -05:00
|
|
|
npm help folders
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-18 21:01:39 +02:00
|
|
|
npm help config
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2019-11-05 14:55:08 -05:00
|
|
|
npm help npmrc
|
2014-09-24 14:41:07 -07:00
|
|
|
|
|
|
|
.RE
|