I'm using a nodejs code to generate a application package, but I want to check if a certain string is written in a text file. I only want to generate the application if the string is indeed in the text file.
I'm using this function to check that:
function checkValid(err, data) {
fs.readFile('http://domain.com/directory/data.txt', function (err, data) {
if (err) throw err;
if(data.indexOf('milk') < 0){
console.log(data)
}
});
}
//end of valid checker
And here I'm calling the function: async.parallel(callItems, function(err, results) {
if(err) {
console.error("**** ERROR ****");
} else {
checkValid(err, data);
// Here I'm checking
createSourceDirectories(destDir, packageName);
copySourceDirectories(destDir, packageName);
removeBootstrapDirectories(destDir);
sendContentAsZip(destDir, res);
}
});
Please, you can check my whole code at: http://pastebin.com/2d7LtBgb
Everytime it returns an error, any idea? and preferably any (noob proof, I'm a very beginner) solutions.
Are you sure you can directly read a remote file with the "read" method?