I'm using node-redis module to connect to redis.
So, I'm attaching an event listener to handle the case where redis server connection cannot be established.
client = redis.createClient(6379, 'localhost')
client.on('error',(err)=>{
console.log('redis connection refused')
})
This is the error that occurs without the listener.
events.js:141
throw er; // Unhandled 'error' event
^
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:837:11)
at exports._exceptionWithHostPort (util.js:860:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)
Now my question is, when does this event listener get attached to 'client'. Is it possible that the connection refused error be thrown before the event listener is attached?