Node.js domains in Express app middleware -


i believe following code might useful handle exceptions occur requests:

var domain = require('domain');  app.use(function(req,res,next){      var d = domain.create();      d.on('error',function(err){       res.json({error: err.stack});     });      d.run(function(){        next();     });  }); 

however, read type of code can leak memory. not sure understand why. there way avoid leaking memory? perhaps should manually remove event handling , listeners domain after response stream closed? how allow domain object garbage collected?


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

c++ - How to test/verify that zero-initialization takes place -

node.js - Webpack/TypeScript Raising Errors When node_modules is Excluded -