简体   繁体   English

如何在Node.js中获取全局模块安装文件夹

[英]How to get the global module installation folder in Node.js

I'm trying to access the location on the disk of the global node modules (from within a node module). 我正在尝试访问全局节点模块的磁盘上的位置(从节点模块中)。

I know I can enter npm root -g on the command line, but this is awfully SLOW. 我知道我可以在命令行输入npm root -g ,但这非常慢。

Does any of you know a way to get this information reliably and in a timely fashion (without requiring users to setup any global Env variables)? 您是否知道如何可靠且及时地获取此信息(无需用户设置任何全局Env变量)?

You probably cannot do this in pure javascript way, but you can just look for the npm location: 您可能无法以纯JavaScript方式执行此操作,但您只需查找npm位置:

$ which npm
/usr/local/bin/npm
$ ls -al /usr/local/bin/npm
... /usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

so the global node_modules is /usr/local/lib/node_modules 所以全局node_modules/usr/local/lib/node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM