Change
var restlerHtmlFile = function(Url) {
rest.get(Url).on('complete', function(result) {
fs.writeFileSync('file.html',result);
});
};
if(require.main == module) {
restlerHtmlFile('http://obscure-refuge-7370.herokuapp.com/');
fs.readFileSync('file.html');
}
to
var restlerHtmlFile = function(Url) {
rest.get(Url).on('complete', function(result) {
fs.writeFileSync('file.html',result);
fs.readFileSync('file.html');
});
};
if(require.main == module) {
restlerHtmlFile('http://obscure-refuge-7370.herokuapp.com/');
}
Second parameter to rest.get(Url).on
is an asynchronous call back function, which will be called when complete
occurs and only then the file gets created. But you are reading the file, even before the complete
occurs. Thats why you are getting this error.