`npm link --save` does not update dependencies on my package.json

node.js, npm

Solution

According the npm docs, `npm link` is not intended to change your `package.json`. It creates symbolic links on your file system for a package.

This allows you to still reference a module by name, but have it pull from your local filesystem:

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

If you actually intend to insert a file path in your `package.json`, use `npm install` instead:

npm install --save /path/to/package

Then you'll see a reference in `package.json` file:

"dependencies": {
  "local-package": "file:/path/to/package"
}

Though I highly recommend you use `npm link` instead, as it makes your `package.json` more portable. If you commit your changes with local file paths, it may become invalid on another system, or if you move around the files.

Problem

I am using `npm link package --save` to create a local link to a globally installed package. It correctly creates the link to the package (and would install it globally in case it were not already installed); but it fails to update the dependencies in `package.json`. What I am missing here?

Original source