learnyounode
learnyounode copied to clipboard
http collect
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.
Have you tried using ES5 functions instead of arrow?