Book Image

Mastering JavaScript Promises

Book Image

Mastering JavaScript Promises

Overview of this book

Table of Contents (16 chapters)
Mastering JavaScript Promises
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Familiarizing Node.js – the Q way


When you're working with functions that make use of the Node.js callback pattern, where callbacks are in the form of function(err, result), Q provides a few advantageous service functions for adapting between them. The two most important functions are: Q.nfcall() and Q.nfapply():

  • Q.nfcall(): The Node.js function call

    return Q.nfcall(FS.readFile, "foo.txt", "utf-8");
  • Q.nfapply(): The Node.js function apply

    return Q.nfapply(FS.readFile, ["foo.txt", "utf-8"]);

They are both used for calling functions with the same resemblance of Node.js so that they can generate promises.