[英]How to compare the contents of two .js files using node js
I have two.js files with several functions defined in them and I wish to compare the contents of these two files.我有两个 .js 文件,其中定义了几个函数,我想比较这两个文件的内容。 Is there an npm package for such a comparison or any other way to do this?是否有 npm package 用于这样的比较或任何其他方式来做到这一点?
You just need to compare them as if they were 2 plain text files.您只需要将它们作为 2 个纯文本文件进行比较。 You could do something like this:你可以这样做:
function readFile(name) {
return new Promise((resolve, reject) =>
fs.readFile(name, function (err, data) {
if (err) { reject(err); }
resolve(data);
});
});
}
Promise.all(readFile('file1'), readFile('file2')).then(data => {
var file1 = data[0];
var file2 = data[1];
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.