Skip to content

Instantly share code, notes, and snippets.

@cajones
Last active August 29, 2015 13:56
Show Gist options
  • Save cajones/9052737 to your computer and use it in GitHub Desktop.
Save cajones/9052737 to your computer and use it in GitHub Desktop.
Q example
var Q = require('Q');
var mongo = require('mongodb').MongoClient;
var main = function(){
connect('mongodb://localhost')
.then(close)
.catch(logError);
};
function connect(url) {
return Q.nfncall(mongo.connect, url);
}
function close(db) {
return Q.nfncall(db.close)
.then(function () {
console.log('Finished!');
});
}
function logError(error){
console.dir(error);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment