I just used the async waterfall method but I am confused about calling the function after another. I want to console 'hi' but it is not getting called. Can anyone please suggest help?
exports.inviteAgent = function (req, res) {
var obj = {};
async.waterfall([
function (done) {
var url = config.mailer.inviteAgentUrl;
res.render('modules/users/server/templates/invite-agent', {
name: obj.name,
}, function (err, emailHTML) {
done(err, emailHTML);
});
},
// If valid email, send reset email using service
function (emailHTML, done) {
var mailOptions = {
to: obj.email,
from: config.mailer.from,
subject: 'Invite agent',
html: emailHTML
};
smtpTransport.sendMail(mailOptions, function (err) {
if (err) {
return res.send({ 'respCode': common.statusCodes.COMMON, 'respMessage': errorHandler.getErrorMessage(err) });
} else {
res.jsonp({ 'respCode': common.statusCodes.SUCCESS, 'respMessage': 'Send email successfully' });
done(done);
}
});
},
function (done) {
console.log('hi')
}
], function (err) {
});
};
I think you are not handling the callbacks or done functions in this case properly. Try this out