Skip to content

Instantly share code, notes, and snippets.

@tastywheat
Created January 10, 2016 13:32
Show Gist options
  • Select an option

  • Save tastywheat/e21d700012d6e18f5a09 to your computer and use it in GitHub Desktop.

Select an option

Save tastywheat/e21d700012d6e18f5a09 to your computer and use it in GitHub Desktop.
uncaught exception email notification
var nodemailer = require('nodemailer')
var transport = nodemailer.createTransport('SMTP', { // [1]
service: "Gmail",
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
})
if (process.env.NODE_ENV === 'production') { // [2]
process.on('uncaughtException', function (er) {
console.error(er.stack) // [3]
transport.sendMail({
from: 'alerts@mycompany.com',
to: 'alert@mycompany.com',
subject: er.message,
text: er.stack // [4]
}, function (er) {
if (er) console.error(er)
process.exit(1) // [5]
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment