Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.