Very simply, I'm mapping a route in my express/node app to a method in another module. On completion, an event is dispatched. All works great, but how do I get at res in my 'on_products' event handler?
Here is the general idea:
Routes = (app) ->
eventbus.on 'on_products', -> res.send 'some products' #how do i get at res here?
app.get '/products', (req,res) -> getProducts()
module.exports = Routes
Thanks in advance.
You can pass along arguments when you trigger the event:
eventbus.emit 'on_products', res
And use that in the event handler:
eventbus.on 'on_products', (res) ->
res.send 'some products'