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 callreturn Q.nfcall(FS.readFile, "foo.txt", "utf-8");
Q.nfapply()
: The Node.js function applyreturn 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.
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.