Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active August 17, 2019 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/8c6900857e78189892429099a439eeac to your computer and use it in GitHub Desktop.
Save ORESoftware/8c6900857e78189892429099a439eeac to your computer and use it in GitHub Desktop.
Using Node.js domains in production
app.use(function(req,res,next){
const d = Domain.create(); // create a new domain for this request
res.once('finish', function () {
d.exit();
d.removeAllListeners();
});
d.once('error', function (e) {
if (!res.headersSent) {
res.status(500).json({
error: e && e.stack || util.inspect(e || 'no error trace available')
});
}
});
// we invoke the next middleware
d.run(next);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment