[英]Find the file system location of an installed NodeJS module
I'm looking at the below code from the grunt-template-jasmine-istanbul project on GitHub; 我正在看GitHub上grunt-template-jasmine-istanbul项目中的以下代码;
var DEFAULT_TEMPLATE = __dirname + '/../../../../grunt-contrib-jasmine/tasks/'
+ 'jasmine/templates/DefaultRunner.tmpl';
I've noticed before that you can (not that you necessarily should) require internals from a NodeJS module like so; 我之前注意到,您可以(并非一定要)从NodeJS模块中获取内部信息,例如:
console.log(require('grunt/package.json'));
But in this case the file is an Underscore.js template, so you can't require it. 但是在这种情况下,该文件是Underscore.js模板,因此您不需要它。
Is there a way to find the install location (which can differ) of an npm module in order to harden this a little? 是否可以找到一个npm模块的安装位置(可以有所不同),以便对此进行一些强化?
require.resolve(moduleName) require.resolve(moduleName)
should do the trick for locally installed node_modules 应该为本地安装的node_modules做花招
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.