I've been trying to read a txt file from a URL and output my own text file using nodejs
Can anyone tell me what am I doing wrong in my code?
var fs = require('fs');
var request = require('request');
var stream = fs.createWriteStream("my_file.txt");
request('http://redsismica.uprm.edu/Data/prsn/EarlyWarning/Catalogue.txt', function (error, response, body) {
if (!error && response.statusCode == 200) {
firstLine = body.substring(0, body.indexOf('\n'));
console.log(firstLine);
stream.once('open', function(fd) {
wstream.write(firstLine, 'utf16le');//stream.write(firstLine);
stream.end();
});
}
})