source: trip-planner-front/node_modules/needle/examples/stream-events.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 538 bytes
RevLine 
[6a3a178]1var needle = require('./..');
2
3var resp = needle.get('google.com', { follow_max: 10, timeout: 5000 });
4
5resp.on('readable', function() {
6 var chunk;
7 while (chunk = this.read()) {
8 console.log('Got ' + chunk.length + ' bytes');
9 }
10})
11
12resp.on('headers', function(headers) {
13 console.log('Got headers', headers);
14})
15
16resp.on('redirect', function(url) {
17 console.log('Redirected to url ' + url);
18})
19
20resp.on('done', function(err) {
21 console.log('Finished. No more data to receive.');
22 if (err) console.log('With error', err)
23})
Note: See TracBrowser for help on using the repository browser.