Asynchronous JavaScript code using promises can be very expressive, especially if you do not create unnecessary promises. For example, I would like to list all files in given folder with extension .md:
1 | var Q = require('q'); |
The code works, but it has 5-6 lines of boilerplate code (creating and resolving deferred object) for 1 action line (globbing folder). Lets shorten this.
Q promises library I often use has a denodeify method to convert Nodejs callback functions into promise returning ones.
1 | var Q = require('q'); |
I would argue that grabMarkdownFiles
function becomes unnecessary.
Loading Q just to adapt glob also seems like overhead
1 | var glob = require('q').denodeify(require('glob')); |
So we went from 10 lines to 2. Not bad.