Q utilities for Node.js

In this chapter, we came to know that promises are getting more easy to use within Node.js. The following is the set of all major utilities offered by Q for using Node.js:

  • Q.nfapply(fs.readFile, [filename, encoding]).then(console.log);
  • Q.nfcall(fs.readFile, filename, encoding).then(console.log);
  • Q.nfbind(fs.readFile)(filename, encoding).then(console.log);
  • Q.npost(fs, "readFile", [filename, encoding]).then(console.log);
  • Q.nsend(fs, "readFile", filename, encoding).then(console.log);

Q has more to offer, but the preceding ones are the best and most used and sensible use of these can help us write a more manageable, cleaner, and dynamically controlled mechanism.

Get Mastering JavaScript Promises now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.