HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/node_modules/pm2/node_modules/needle/examples/stream-events.js
var needle = require('./..');

var resp   = needle.get('google.com', { follow_max: 10, timeout: 5000 });

resp.on('readable', function() {
  var chunk;
  while (chunk = this.read()) {
    console.log('Got ' + chunk.length + ' bytes');
  }
})

resp.on('headers', function(headers) {
  console.log('Got headers', headers);
})

resp.on('redirect', function(url) {
  console.log('Redirected to url ' + url);
})

resp.on('done', function(err) {
  console.log('Finished. No more data to receive.');
  if (err) console.log('With error', err)
})