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
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
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)
On Unix systems, global libraries are typically stored in:
Windows systems have different paths:
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
Installing Modules Globally vs. Locally
When installing modules, the -g option can be used to install them globally:
npm install -g pm2
For local installation within the current project:
npm install pm2
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!