Why Is My Node Event Callback Showing Up In The Event As Undefined?
I am trying to pass back a url string as 'data' into my eventhandler. My request to the server is 'https://172.20.10.6/index.html'. The console.log below prints out '/index.html'
Solution 1:
It looks like you're swallowing errors.
if(err, data) {
console.log('error geting data');
}
That condition (err, data)
will ignore the value of err
. If data
is undefined, it will be falsy and you won't know that you had an error. You probably want something more like this:
if (err) {
console.log('error getting data')
}
Tracing back to your emitter, you are emitting in a way that sends your data to the first argument, which should be where the error goes. So this:
ee.emit("dataIn", req.url);
...should be more like this:
ee.emit("dataIn", null, req.url);
Post a Comment for "Why Is My Node Event Callback Showing Up In The Event As Undefined?"