sindresorhus / guides

A collection of succinct guides - Public Domain
2.47k stars 458 forks source link

Missing `NODE_PATH` line #42

Closed benjamin-rood closed 7 years ago

benjamin-rood commented 7 years ago

This addition matches the original SO answer http://stackoverflow.com/questions/10081293/install-npm-into-home-directory-with-distribution-nodejs-package-ubuntu/13021677, which was necessary to actually get it working.

sindresorhus commented 7 years ago

It's intentionally left out. NODE_PATH is an anti-pattern.

Exposing binaries is covered by the PATH="$NPM_PACKAGES/bin:$PATH" line.

From the Node.js docs:

NODE_PATH was originally created to support loading modules from varying paths before the current module resolution algorithm was frozen.

NODE_PATH is still supported, but is less necessary now that the Node.js ecosystem has settled on a convention for locating dependent modules. Sometimes deployments that rely on NODE_PATH show surprising behavior when people are unaware that NODE_PATH must be set. Sometimes a module's dependencies change, causing a different version (or even a different module) to be loaded as the NODE_PATH is searched.

These are mostly for historic reasons. You are highly encouraged to place your dependencies locally in node_modules folders. They will be loaded faster, and more reliably.

benjamin-rood commented 7 years ago

Cool, appreciate the explanation. It was necessary for me to get it working, but I recognise that may be because of some misconfiguration elsewhere.