Local installation of a NPM package limits the impact of a package to a project folder. Unlike a global install that exposes potentially the package on the entire machine. The location of executables is not the same in both cases.
- Requirements :
- Install Node.js and npm
Local
Install
To install a package locally, run from a project folder :
npm install package-name
Run
Unlike a globally installed package that can run potentially from anywhere, the executable of a locally installed package is located in a subfolder of the project :
./node_modules/.bin
See an example: run a local browser-sync on the command line
Global
Install
To install a package globally, run from anywhere :
npm install -g package-name
(or npm install --global package-name)
Run
Unlike a locally installed package, the executable of a globally installed package is in a common folder.
For example, on Windows, the executable is in:
%USERPROFILE%\ AppData\Roaming\npm
As long as you add this location to your PATH
environment variable, you can run this executable from anywhere.
See an example: run a global browser-sync on the command line