Answer the question
In order to leave comments, you need to log in
Error with catching asynchronous error module domain ( node js )?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Answer the question
In order to leave comments, you need to log in
Ideally, each request should have its own domain.
var createDomain = require('domain').create;
var app = express();
var times = 0;
function domainMiddleware () {
return function (req, res, next) {
var domain = createDomain();
domain.id = Date.now() + (times++);
domain.add(req);
domain.add(res);
domain.run(function() {
next();
});
domain.on('error', function(e) {
next(e);
});
}
}
app.use(domainMiddleware());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question