Saturday, 27 May 2017

Reading remote CSV with Node JS

I have the following problem: I'm trying to read a remote CSV from another website, and whenever I use a http.get, I get a status code 410 Gone. Chrome can download it just fine, also the other site loads these CSVs as well.

var options = {
    host: myHost,
    port: 80,
    path: myURL,
    method: 'GET',
    headers: {
        'Content-disposition': 'attachment; filename='someFile.csv',
        'Content-Type': 'text/csv'
    }
};

http.get(options, function(res) {
    var str = '';
    res.on('data', function(chunk) {
        str += chunk;
    });
    res.on('end', function() {
        console.log(str);
    });
});

I tried using require, but I get the same thing. What's the proper way to go about this?



via Stir Zoltán

No comments:

Post a Comment