Alex B Alex B - 5 months ago 13
Node.js Question

success ? 'sent' : 'failed' defaults to 'sent' for success = null. Why?

I'm playing around with emailing from nodeJS (using the nodemailer lib), and I'm currently hitting some timeouts on the whole mailing process. That's not the problem I'd need help with. The problem I do need help with is that success will be null when it hits the logging part, and sole.log('Message ' +that makes the whole console.log statement to output "sent". No "Message", no failed.

Any idea why?

nodemailer.send_mail(
// e-mail options
{
to:"alexsb92@gmail.com",
sender:"alexsb92@gmail.com",
subject:"node_mailer test email",
html:'<p><b>Hi,</b> how are you doing?</p>',
body:'Hi, how are you doing?'
},
// callback function
function(error, success){
console.log('Message ' + success ? 'sent' : 'failed');
}
);

Answer

Operator precedence? Try:

'Message ' + (success ? 'sent' : 'failed')
Comments