Callbacks and other approaches
Promises is a technique to organize asynchronous code callbacks into the objects. That’s in its name. Asynchronous call returns us an object as a promise of further result or error callback. There are several libraries to implement Promises scheme. E.g., Q [http://documentup.com/kriskowal/q] and Bluebird [http://bluebirdjs.com/docs/getting-started.html]. Bluebird is much faster and better than Q, because Q has a lot of stuff at line of code security in the browser. Thus, use Bluebird both on the server side and as front-end asynchronous model.
Regular promise object has then method where we specify what action should be done on successful finish of the asynchronous call a promise keep an eye on. There may be another promise as well. As you see, we have a queue of promises called one by one asynchronously. Regular callback has special argument to indicate an error as a result of operation. Promises allows us to catch the error in any place of the queue by catch method. Usually, we put error handler at the end of the sequence of asynchronous calls. It’s easy to convert callbacks into promises. There is promisify process to generate promises version of regular callback-based methods.