Difference between `npm link x` and `npm install /path/to/x`

An article on Medium by Alex Mills lays it out bare.

It says the difference between npm link x and npm install /local/path/to/x are:

  1. The big difference is that npm install /local/path/x will
    run the preinstall/postinstall hooks, but npm link x will not.

  2. npm link uses the global NPM space, npm install /local/path/x does not. npm link creates a symlink to x
    in the global space, and then when you call npm link x from
    y, it creates a symlink not directly to x, but rather to
    the global symlink. This is an important differences if you are
    using different global node.js versions, e.g., NVM.

  3. npm install /absolute/path/x will alter package.json, npm link x
    does not.

To get a fresh local copy instead of a symlink, use npm pack, like so:

tgz="$PWD/$(npm pack)"
cd <other project>
npm install "$tgz"

You could also use cp/rsync, but that wouldn’t run install hooks or put the executables in node_modules/.bin…that will work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)