I'm working with Mongoose, and I'd like to use a promise approach with the Q library.
Not sure when to use the various methods nfcall,nfinvoke or wrap the APIs with denodeify/nfbind
Examples:
var p = Q.when(User.findOne({login: 'johndoe'}).exec());
p.then(...)
Or Something like:
Q.ninvoke(User, 'findOne', '{login:"johndoe"}').then(...)
Or wrapping the API like:
'use strict';
//pUser.js Q/promise wrapper
var Q = require('q'),
mongoose = require('mongoose'),
User = mongoose.model('User');
exports.findOne = function() {
return Q.denodefiy(User.findOne);
}
//and then use like:
var pUser = require('pUser');
pUser.findOne({...}).then(function(user) { ... });
I've also seen approaches like this which wrap every method with an nfbind or something similar
Thanks