stream-events.js 538 B

1234567891011121314151617181920212223
  1. var needle = require('./..');
  2. var resp = needle.get('google.com', { follow_max: 10, timeout: 5000 });
  3. resp.on('readable', function() {
  4. var chunk;
  5. while (chunk = this.read()) {
  6. console.log('Got ' + chunk.length + ' bytes');
  7. }
  8. })
  9. resp.on('headers', function(headers) {
  10. console.log('Got headers', headers);
  11. })
  12. resp.on('redirect', function(url) {
  13. console.log('Redirected to url ' + url);
  14. })
  15. resp.on('done', function(err) {
  16. console.log('Finished. No more data to receive.');
  17. if (err) console.log('With error', err)
  18. })