I'm trying to download a json file from an external url using nodejs.
The problem is that this file (dumpFile.json
) is created empty.
var file = fs.createWriteStream("download/dumpFile.json");
let URL = 'http://user:pass@domain.com/file.json');
var request = http.get(URL, function (resp) {
resp.on("finish", function () {
logger.error(fs.readFileSync("file", { encoding: "utf8" }))
}).pipe(file);
});
}).catch(error => {
logger.error(error)
})
I tried a lot of things, but I can't figured it out what is happening.