Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
Read the npm guide if you are starting out with npm, it will go into a lot of the basic details.
When you install a package with npm (or yarn), you can do two types of installation:
- a local install
- a global install
By default, when you type an npm install command, like:
npm install lodash
the package is installed in the current directory, under the node_modules subfolder.
As this happens, npm also adds the lodash entry in the dependencies property of the package.json file present in the current folder.
A global installation is performed using the -g flag:
npm install -g lodash
When this happens, npm won’t install the package under the local folder, but instead, it will use a global location.
Where, exactly?
The npm root -g command will tell you where that exact location is on your machine.
On macOS or Linux this location could be /usr/local/lib/node_modules.
On Windows it could be C:\Users\YOU\AppData\Roaming\npm\node_modules
If you use nvm to manage Node.js versions, however, that location would differ.
If you use nvm to manage Node versions, the path is under your nvm directory (e.g. ~/.nvm/versions/node/v8.9.0/lib/node_modules).