Skip to content

Instantly share code, notes, and snippets.

@nmmmnu
Created September 8, 2014 19:44
Show Gist options
  • Save nmmmnu/7b0d9c5f9f60f54cfbd9 to your computer and use it in GitHub Desktop.
Save nmmmnu/7b0d9c5f9f60f54cfbd9 to your computer and use it in GitHub Desktop.
NodeJS Q Promises Demo
var fs = require('fs');
var Q = require("q");
/*
Q.all(
[
Q.ninvoke(fs, "readFile", "/etc/hosts", "utf8")
]
)
*/
Q.ninvoke(fs, "readFile", "/etc/hosts", "utf8")
.then(
function(data){
console.log(data);
return Q.ninvoke(fs, "readFile", "/etc/passwd", "utf8");
}
).then(
function(data){
console.log(data);
}
).fail(
function(err){
console.log(err);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment