learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

http collect

Open artivilla opened this issue 8 years ago • 1 comments

I've tried this in a few different ways. Here's one implementation and I keep getting the same error. Any suggestions? The same thing seems to work with the bl library, so I'm not sure what's the difference here.

'use strict'
let http = require('http')
let concat = require('concat-stream')

http.get(process.argv[2], (res) => {
  var result
  res.pipe(concat(function (data) {
    result = data.toString()
    console.log(result)
  }))
  res.on('end', console.log(result))
  res.on('error', console.log('thowing an err'))
})

I'm guessing a 'throw new TypeError('listener must be a function');' error.

artivilla avatar Mar 02 '16 00:03 artivilla

Have you tried using ES5 functions instead of arrow?

MystK avatar Mar 29 '16 03:03 MystK