0

I am new to node.js and am currently setting up the environment, choosing which modules I will use etc. During my research I found the Q module - which I really appreciate because of both the simplicity of the code and the structure itself. I started to search for some discussion about the pros and cons of using promises with node.js. But, unfortunately, I could not find many information. Now I ask myself why.

Do you recommend using promises with node.js? Or are there any known disadvantage what might should stop me from using it?

Christopher Will
  • 2,991
  • 3
  • 29
  • 46

1 Answers1

3

promises arent strictly a node.js thing (jQuery uses promises). mostly its just cleaner code compared to callbacks.

here is a nice slideshare about that topic: http://de.slideshare.net/domenicdenicola/callbacks-promises-and-coroutines-oh-my-the-evolution-of-asynchronicity-in-javascript

slide 70 provides a link to a module you can use (even in node.js) which makes it even easier for you to use promises in your code (the q-module)

hereandnow78
  • 14,094
  • 8
  • 42
  • 48
  • Thanks for the link. I'm going to give this a go because it looks quite interesting; particularly when I'm trying to set up hundreds of parallel connections to back end servers. So far I'm using a state machine in an array but this could be a "cleaner" way? Will see.. – PP. Jun 20 '13 at 10:28
  • Thanks for the link, as well. But still this is another general explanation about the benefits of using promises. So I am still wondering why, for instance, most node.js books do not cover this topic at all. Though I will give it a try, I am still bit doubtful if this decision might lead me to some disadvanteges in the future. – Christopher Will Jun 20 '13 at 12:26
  • I just found a nice article about why promises are not so wide spreaded. http://www.futurealoof.com/posts/broken-promises.html The main point is to follow the eco-system and to be compatible to each other. – Christopher Will Jun 20 '13 at 13:49