I have this code in one of my projects. The problem is that it isn’t downloading any file, don’t get me wrong, it works in my own pc but in my workspace isn’t working, I wonder if I’m not allowed to download or something like that. I would really appreciate any help.
function downloadFile(url, dest, cb) {
// first check if file doesn't already exist
fs.stat(dest, function (err, stat) {
if (!(err == null) && err.code === 'ENOENT') {
var file = fs.createWriteStream(dest);
https.request(url, function (response) {
response.pipe(file);
file.on('finish', function () {
file.close(cb);
});
}).on('error', function (err) {
fs.unlink(dest);
if (cb) {
cb(err.message);
} else {
console.log(err);
}
});
}
});
}