I'm trying to read the content from a URL with Node.js but all I seem to get are a bunch of bytes. I'm obviously doing something wrong but I'm not sure what. This is the code I currently have:
var http = require('http'); var client = http.createClient(80, "google.com"); request = client.request(); request.on('response', function( res ) { res.on('data', function( data ) { console.log( data ); } ); } ); request.end();
Any insight would be greatly appreciated.
Or if you don't need to save to a file first, and you just need to read the CSV into memory, you can do the following: var request = require('request'); request. get('http://www.whatever.com/my.csv', function (error, response, body) { if (!
try using the on error event of the client to find the issue.
var http = require('http'); var options = { host: 'google.com', path: '/' } var request = http.request(options, function (res) { var data = ''; res.on('data', function (chunk) { data += chunk; }); res.on('end', function () { console.log(data); }); }); request.on('error', function (e) { console.log(e.message); }); request.end();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With