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