top | item 5185450

Ask HN: How do you deal with the NodeJS Pyramid of Doom?

6 points| rudyjahchan | 13 years ago

What's your preferred method for dealing with the Pyramid Of Doom; fibers (via fibrous)? AsyncBlock? Or should we all use Promises?

6 comments

order
[+] hacknat|13 years ago|reply
Instead of using lambdas why not name your functions (function expression) and pass those around instead like so:

var someFunc1 = function(){...}

var somFunc2 = function(){...}

someNodeBinder1(someFunc1);

someNodeBinder2(someFunc2);

That being said, this is why it is best to avoid large projects with node.

[+] tferris|13 years ago|reply
> That being said, this is why it is best to avoid large projects with node.

Like Airbnb, Linkedin and MySpace?? You can handle even large codebases well with Node. Callback hell is overrated since a large chunk of your code still stays synchronous for most server side rendered Node.js sites. At the end you implement user concurrency not in your app rather in some load balancing entity abstracting this away from you core app logic. Then, writing a Node app isn't much different than writing a Ruby or Python app (if using the right patterns/tools/libs).

And you get amazing speed: I think most didn't get how fast Node.js is -- it's factor 100 compared to any other traditional scripting language (i.e. Ruby). Once people learned this they won't go back.

[+] klapinat0r|13 years ago|reply
I'm not familiar with the "Pyramid of Doom" term, but I'm guessing Callback Hell? Apart from the mentioned use of promises, here's a short writeup of how to avoid getting lost in the abyss http://callbackhell.com/
[+] TheMakeA|13 years ago|reply
I would probably be using promises now if more libraries supported them. It seems like for now I'm left having to wrap functions myself... (let me know if I'm wrong!)