If you do not know anything about promises they are worth checking out. In a nut shell promises are a great way to handle anything that needs to be done in an async kind of way and or anything that may result in a pass or fail result.
If you are not going to bother with promises one alliterative is to have high level functions with pass and fail callbacks, although it works things can get a little messy. As such a lot of developers like to use promises.
Take into account the following code.
This is an example of something where there are two possible outcomes, one where I will be getting the stats of a readme file logged to the console, and another in the event that some kind of error happens. As such the above example can be written as a promise like this:
In the above example I am using the built in Promise constructor that comes in any version of node that supports promises. In most cases it works okay, but bluebird provides a few more features, some of which are pretty helpful.
so add it to a project can check it out:
This is a great method in bluebird as it can quickly turn a node.js function like fs.stat used in the above example, and turn it into a promise.
As such the above example I gave that uses the built in node.js Promise constructor can be simplified to just this with bluebird.
It is common practice to overwrite (or monkey patch) the built in Promise Constructor but for this post I decided not to in order to compare what it is that is gained in features. In production I see no reason why not though bluebird just gives you a more powerful, and capable Promise constructor with additional helpful methods like this.
There are many more methods to write about, as well as a whole lot more to write about when it comes to promises in general, for now there is the bluebird website that is pretty helpful if you want to learn more about that api.