我需要检查模块是否属于某个版本。
我可以通过执行以下操作检查模块是否存在于同一文件夹中:
var other;
try {
other = require("../theOtherModule");
} catch(e){
// module doesn't exist or something
}
但是,这并没有告诉我该模块的版本。我需要能够判断该模块是否是某个版本或更高版本。
最佳答案
我认为没有内置函数可以做到这一点。相反,您可以从 package.json 文件获取版本:
var packageJson = require('./package.json');
console.log(packageJson.version);
关于javascript - 检查模块版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27328240/