Home > Web Front-end > JS Tutorial > Where Do npm-Installed Node.js Modules Reside?

Where Do npm-Installed Node.js Modules Reside?

Barbara Streisand
Release: 2024-12-08 00:17:14
Original
545 people have browsed it

Where Do npm-Installed Node.js Modules Reside?

Finding the Location of Installed Node.js Modules via npm

When working with Node.js, understanding where installed modules are stored is crucial. npm, the primary package manager for Node.js, handles this process seamlessly.

Global Libraries

Global libraries are accessible from any project. To find their location, execute the command:

npm list -g
Copy after login

This will display a list of installed global libraries and their paths. For a truncated output showing only the path, use the following command:

npm list -g | head -1
Copy after login

To view only the main packages without their sub-packages, use the commands:

npm list --depth=0
npm list -g --depth=0 (for global packages only)
Copy after login

On Unix systems, global libraries are typically stored in:

  • /usr/local/lib/node
  • /usr/local/lib/node_modules

Windows systems have different paths:

  • Windows XP: %USERPROFILE%AppDatanpmnode_modules
  • Windows 7, 8, and 10: %USERPROFILE%AppDataRoamingnpmnode_modules

Non-Global Libraries

Non-global libraries, used within a specific project, are stored in the node_modules subfolder of the project directory. To see the installed non-global libraries for your current project:

npm list
Copy after login

Installing Modules Globally vs. Locally

When installing modules, the -g option can be used to install them globally:

npm install -g pm2
Copy after login

For local installation within the current project:

npm install pm2
Copy after login

This distinction determines the location where the installed module can be accessed.

The above is the detailed content of Where Do npm-Installed Node.js Modules Reside?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template