parsed-stream.js 535 B

1234567891011121314151617181920212223
  1. //////////////////////////////////////////
  2. // This example demonstrates what happends
  3. // when you use the built-in JSON parser.
  4. //////////////////////////////////////////
  5. var fs = require('fs'),
  6. stream = require('stream'),
  7. needle = require('./../');
  8. var url = 'http://ip.jsontest.com/',
  9. resp = needle.get(url, { parse: true });
  10. resp.on('readable', function(obj) {
  11. var chunk;
  12. while (chunk = this.read()) {
  13. console.log('root = ', chunk);
  14. }
  15. });
  16. resp.on('done', function() {
  17. console.log('Done.');
  18. });