npm-link.1 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .TH "NPM\-LINK" "1" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-link\fR \- Symlink a package folder
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm link (in package dir)
  9. npm link [<@scope>/]<pkg>[@<version>]
  10. alias: npm ln
  11. .fi
  12. .RE
  13. .SS Description
  14. .P
  15. Package linking is a two\-step process\.
  16. .P
  17. First, \fBnpm link\fP in a package folder will create a symlink in the global folder
  18. \fB{prefix}/lib/node_modules/<package>\fP that links to the package where the \fBnpm
  19. link\fP command was executed\. It will also link any bins in the package to \fB{prefix}/bin/{name}\fP\|\.
  20. Note that \fBnpm link\fP uses the global prefix (see \fBnpm prefix \-g\fP for its value)\.
  21. .P
  22. Next, in some other location, \fBnpm link package\-name\fP will create a
  23. symbolic link from globally\-installed \fBpackage\-name\fP to \fBnode_modules/\fP
  24. of the current folder\.
  25. .P
  26. Note that \fBpackage\-name\fP is taken from \fBpackage\.json\fP,
  27. not from directory name\.
  28. .P
  29. The package name can be optionally prefixed with a scope\. See npm help \fBscope\fP\|\.
  30. The scope must be preceded by an @\-symbol and followed by a slash\.
  31. .P
  32. When creating tarballs for \fBnpm publish\fP, the linked packages are
  33. "snapshotted" to their current state by resolving the symbolic links\.
  34. .P
  35. This is handy for installing your own stuff, so that you can work on it and
  36. test it iteratively without having to continually rebuild\.
  37. .P
  38. For example:
  39. .P
  40. .RS 2
  41. .nf
  42. cd ~/projects/node\-redis # go into the package directory
  43. npm link # creates global link
  44. cd ~/projects/node\-bloggy # go into some other package directory\.
  45. npm link redis # link\-install the package
  46. .fi
  47. .RE
  48. .P
  49. Now, any changes to ~/projects/node\-redis will be reflected in
  50. ~/projects/node\-bloggy/node_modules/node\-redis/\. Note that the link should
  51. be to the package name, not the directory name for that package\.
  52. .P
  53. You may also shortcut the two steps in one\. For example, to do the
  54. above use\-case in a shorter way:
  55. .P
  56. .RS 2
  57. .nf
  58. cd ~/projects/node\-bloggy # go into the dir of your main project
  59. npm link \.\./node\-redis # link the dir of your dependency
  60. .fi
  61. .RE
  62. .P
  63. The second line is the equivalent of doing:
  64. .P
  65. .RS 2
  66. .nf
  67. (cd \.\./node\-redis; npm link)
  68. npm link redis
  69. .fi
  70. .RE
  71. .P
  72. That is, it first creates a global link, and then links the global
  73. installation target into your project's \fBnode_modules\fP folder\.
  74. .P
  75. Note that in this case, you are referring to the directory name, \fBnode\-redis\fP,
  76. rather than the package name \fBredis\fP\|\.
  77. .P
  78. If your linked package is scoped (see npm help \fBscope\fP) your link command must include that scope, e\.g\.
  79. .P
  80. .RS 2
  81. .nf
  82. npm link @myorg/privatepackage
  83. .fi
  84. .RE
  85. .SS See Also
  86. .RS 0
  87. .IP \(bu 2
  88. npm help developers
  89. .IP \(bu 2
  90. npm help package\.json
  91. .IP \(bu 2
  92. npm help install
  93. .IP \(bu 2
  94. npm help folders
  95. .IP \(bu 2
  96. npm help config
  97. .IP \(bu 2
  98. npm help npmrc
  99. .RE