Skip to content

Instantly share code, notes, and snippets.

@tastywheat
Created January 10, 2016 13:32
Show Gist options
  • Save tastywheat/e21d700012d6e18f5a09 to your computer and use it in GitHub Desktop.
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: "[email protected]",
pass: "userpass"
}
})
if (process.env.NODE_ENV === 'production') { // [2]
process.on('uncaughtException', function (er) {
console.error(er.stack) // [3]
transport.sendMail({
from: '[email protected]',
to: '[email protected]',
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