Hacker News new | ask | show | jobs
by latch 5345 days ago
Is that specific to MongoDB on node, or is that just generally true of node.js code though?
2 comments

It's a problem with writing asynchronous code when you have lots of consecutive requests. I don't know if node has something like this but the Tornado team have written http://www.tornadoweb.org/documentation/gen.html which can make such things a little easier
It's generally true for Node when you have a lot of chained I/O. You can somewhat avoid it using events (so you set up event listeners instead of just chaining callbacks endlessly). So far I haven't seen any MongoDB module for Node taking advantage of those (haven't looked a lot yet, though).
I've used EventEmitter on a couple toy projects, but I've always assumed that's adding a bit more overhead to everything than just using callbacks. It's easier to read though and probably easier for someone else to figure out in the future. I've played with node.js libraries that have callbacks strung out over several files, so tracking down exactly where some behavior is happening isn't easy.

There are a few examples out there about using events/listeners, but I think there's room for a really good one.

Using event instead of callback to sequentially get the results with asynchronous way it's a potentially good idea. I also haven't learn much about another Nodejs-MongoDB libraries except the one what I have mentioned there. Please share if you have a follow-up on this technique.
Mongoose is pretty good for succinct Node/MongoDB interaction.