Can someone tell me where can I find the Node.js modules, which I installed using npm
?
If you're trying to access your global dir from code, you can backtrack from process.execPath. For example, to find wsproxy
, which is in {NODE_GLOBAL_DIR}/bin/wsproxy
, you can just:
path.join(path.dirname(process.execPath), 'wsproxy')
There's also how the npm
cli works @ ec9fcc1/lib/npm.js#L254 with:
path.resolve(process.execPath, '..', '..')
See also ec9fcc1/lib/install.js#L521:
var globalPackage = path.resolve(npm.globalPrefix,
'lib', 'node_modules', moduleName(pkg))
Where globalPrefix
has a default set in ec9fcc1/lib/config/defaults.js#L92-L105 of:
if (process.env.PREFIX) {
globalPrefix = process.env.PREFIX
} else if (process.platform === 'win32') {
// c:\node\node.exe --> prefix=c:\node\
globalPrefix = path.dirname(process.execPath)
} else {
// /usr/local/bin/node --> prefix=/usr/local
globalPrefix = path.dirname(path.dirname(process.execPath))
// destdir only is respected on Unix
if (process.env.DESTDIR) {
globalPrefix = path.join(process.env.DESTDIR, globalPrefix)
}
}
You can run npm list -g
to see which global libraries are installed and where they're located. Use npm list -g | head -1
for truncated output showing just the path. If you want to display only main packages not its sub-packages which installs along with it - you can use - npm list --depth=0
which will show all packages and for getting only globally installed packages, just add -g i.e. npm list -g --depth=0
.
On Unix systems they are normally placed in /usr/local/lib/node
or /usr/local/lib/node_modules
when installed globally. If you set the NODE_PATH
environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\AppData\npm\node_modules
Windows 7, 8 and 10 - %USERPROFILE%\AppData\Roaming\npm\node_modules
Non-global libraries are installed the node_modules
sub folder in the folder you are currently in.
You can run npm list
to see the installed non-global libraries for your current location.
npm install -g pm2
- pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules
(Use npm root -g
to check where.)
npm install pm2
- pm2 will be installed locally. It will then typically be found in the local directory in /node_modules
If you are looking for the executable that npm installed, maybe because you would like to put it in your PATH, you can simply do
npm bin
or
npm bin -g
Expanding upon other answers.
npm list -g
will show you the location of globally installed packages.
If you want to output that list to a file that you can then easily search in your text editor:
npm list -g > ~/Desktop/npmfiles.txt
I was beginning to going mad searching the real configuration, so here is the all list of configuration files on linux:
on windows: - c/Program\ Files/nodejs/node_modules/npm/npmrc
Then in the file the prefix is configured:
prefix=/usr
The prefix is defaulted to /usr in linux, to ${APPDATA}\npm in windows
The node modules are under $prefix tree, and the path should contain $prefix/bin
There may be a problem :
/root/.npmrc
may be used! /home/youruser/.npmrc
.npm set -g prefix /usr
it sets the /etc/npmrc global, but doesn't override the localHere is all the informations that were missing to find what is configured where. Hope I have been exhaustive.
In earlier versions of NPM modules were always placed in /usr/local/lib/node or wherever you specified the npm root within the .npmrc file. However, in NPM 1.0+ modules are installed in two places. You can have modules installed local to your application in /.node_modules or you can have them installed globally which will use the above.
More information can be found at https://github.com/isaacs/npm/blob/master/doc/install.md