jpg619/version-bump-tar-2
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-link |
| 3 | section: 1 |
| 4 | description: Symlink a package folder |
| 5 | github_repo: npm/cli |
| 6 | github_branch: release/v6 |
| 7 | github_path: docs/content/commands/npm-link.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/v6/cli-commands/link |
| 10 | - /cli-documentation/v6/cli-commands/npm-link |
| 11 | - /cli-documentation/v6/commands/link |
| 12 | - /cli-documentation/v6/commands/npm-link |
| 13 | - /cli-documentation/v6/link |
| 14 | - /cli-documentation/v6/npm-link |
| 15 | - /cli/v6/cli-commands/link |
| 16 | - /cli/v6/cli-commands/npm-link |
| 17 | - /cli/v6/commands/link |
| 18 | - /cli/v6/link |
| 19 | - /cli/v6/npm-link |
| 20 | --- |
| 21 | |
| 22 | ### Synopsis |
| 23 | |
| 24 | ```bash |
| 25 | npm link (in package dir) |
| 26 | npm link [<@scope>/]<pkg>[@<version>] |
| 27 | |
| 28 | alias: npm ln |
| 29 | ``` |
| 30 | |
| 31 | ### Description |
| 32 | |
| 33 | Package linking is a two-step process. |
| 34 | |
| 35 | First, `npm link` in a package folder 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). |
| 36 | |
| 37 | 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. |
| 38 | |
| 39 | Note that `package-name` is taken from `package.json`, not from directory name. |
| 40 | |
| 41 | The package name can be optionally prefixed with a scope. See [`scope`](/cli/v6/using-npm/scope). The scope must be preceded by an @-symbol and followed by a slash. |
| 42 | |
| 43 | When creating tarballs for `npm publish`, the linked packages are "snapshotted" to their current state by resolving the symbolic links. |
| 44 | |
| 45 | This is handy for installing your own stuff, so that you can work on it and test it iteratively without having to continually rebuild. |
| 46 | |
| 47 | For example: |
| 48 | |
| 49 | ```bash |
| 50 | cd ~/projects/node-redis # go into the package directory |
| 51 | npm link # creates global link |
| 52 | cd ~/projects/node-bloggy # go into some other package directory. |
| 53 | npm link redis # link-install the package |
| 54 | ``` |
| 55 | |
| 56 | 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. |
| 57 | |
| 58 | You may also shortcut the two steps in one. For example, to do the above use-case in a shorter way: |
| 59 | |
| 60 | ```bash |
| 61 | cd ~/projects/node-bloggy # go into the dir of your main project |
| 62 | npm link ../node-redis # link the dir of your dependency |
| 63 | ``` |
| 64 | |
| 65 | The second line is the equivalent of doing: |
| 66 | |
| 67 | ```bash |
| 68 | (cd ../node-redis; npm link) |
| 69 | npm link redis |
| 70 | ``` |
| 71 | |
| 72 | That is, it first creates a global link, and then links the global installation target into your project's `node_modules` folder. |
| 73 | |
| 74 | Note that in this case, you are referring to the directory name, `node-redis`, rather than the package name `redis`. |
| 75 | |
| 76 | If your linked package is scoped (see [`scope`](/cli/v6/using-npm/scope)) your link command must include that scope, e.g. |
| 77 | |
| 78 | ```bash |
| 79 | npm link @myorg/privatepackage |
| 80 | ``` |
| 81 | |
| 82 | ### See Also |
| 83 | |
| 84 | - [npm developers](/cli/v6/using-npm/developers) |
| 85 | - [package.json](/cli/v6/configuring-npm/package-json) |
| 86 | - [npm install](/cli/v6/commands/npm-install) |
| 87 | - [npm folders](/cli/v6/configuring-npm/folders) |
| 88 | - [npm config](/cli/v6/commands/npm-config) |
| 89 | - [npmrc](/cli/v6/configuring-npm/npmrc) |