Domains provide a way to handle multiple different IO operations as a single group. If any of the event emitters or callbacks registered to a domain emit an error event, or throw an error, then the domain object will be notified, rather than losing the context of the error in the process.on('uncaughtException') handler, or causing the program to exit with an error code. Also request level domains allow you to maintain the context of a request.
Questions tagged [node.js-domains]
40 questions
2
votes
2 answers
Is it safe to use domains actually?
In the accepted answer to this question the guy recommends against using domains with throwing exceptions from them because, he says, it will cause memleaks and instability. But this is the way I was going to use domains. Now I'm confused. Is he…

Andrey Kon
- 747
- 2
- 6
- 16
2
votes
1 answer
Node JS - Log worker cluster last exception
I'm working on Node JS server (0.10.30) along with its Cluster feature.
Each time a worker terminates I catch the 'exit' event and restarting a new worker.
I would like to also log (on the master cluster) the reason that worker was terminated, e.g.…

Erez O
- 23
- 4
2
votes
1 answer
node.js domain memory leak
I attach a new domain to each incoming request in my Express app, just like in the example in the node.js doc.
However, I noticed I was leaking memory. When I do a heapdump and inspect it in Chrome, I notice that classes that should be garbaged…

Laurent Perrin
- 14,671
- 5
- 50
- 49
1
vote
1 answer
Bluebird Promises and Domains
I have a issue with throwing an error inside of a bluebird promise. Take the following code:
var Promise = require('bluebird');
var domain = require('domain');
var problem = function() {
return new Promise(function(resolve, reject){
…

Kinetic
- 1,714
- 1
- 13
- 38
1
vote
0 answers
Node.js domains in Express app middleware
I believe the following code might be useful to handle exceptions that occur to certain requests:
var domain = require('domain');
app.use(function(req,res,next){
var d = domain.create();
d.on('error',function(err){
res.json({error:…

Alexander Mills
- 90,741
- 139
- 482
- 817
1
vote
1 answer
Trouble with exiting node domain asynchronously
Is it possible to exit a domain asynchronously with respect to when it was entered? My "stack" mental model of domains is apparently insufficient because I expected this to succeed:
var Domain = require('domain');
var assert =…

Emmett
- 14,035
- 12
- 56
- 81
1
vote
0 answers
Sails.js adding error domains
This is basically a follow up question to an earlier question (found here).
We set up our error handling based off of the response files found in api/responses/. This seems to work for almost all cases, but there does seem to be errors that can…

William Pratt
- 23
- 3
1
vote
1 answer
Do node.js domains need to be disposed? When should it be done?
I have an Express app and I use domains per each request received. I've added a middleware to ensure any further middlewares are executed "inside" a domain.
app.use(function(req, res, next) {
var d = domain.create();
d.req = req;
…

Olegas
- 10,349
- 8
- 51
- 72
1
vote
3 answers
NodeJS Domains and expressjs
Newbie to ExpressJS question:
I am planning on creating a fairly simple (but large) ExpressJS project that responds to REST requests and does read-only DB responses. I have read up about NodeJS domains for capturing errors, but it is not clear to me…

Dr.YSG
- 7,171
- 22
- 81
- 139
1
vote
1 answer
Will node-fibers break node domains?
I'm currently using node-fibers to write synchronous server-side code. I primarily do error handling through try-catch blocks, but there's always a possibility of an error occurring in external libraries or other little bits of asynchronous code. …

josh
- 9,038
- 8
- 31
- 37
1
vote
1 answer
How to add in node.js domain global emitter?
In my node.js application i used to handle error by domain.
The architecture of the app looks like:
Controllers. Express routing calls controllers methods
Controllers call services and use models
Services call repositories
(Actually it's quite…

Iliya Garakh
- 387
- 1
- 4
- 18
1
vote
2 answers
Why NodeJS domains documentation code tries to terminate the process?
In the official NodeJS documentation there is code example where process tries to exit gracefully when there was exception in domain (it closes connections, waits for some time for other requests and then exits).
But why just not send the 500 error…

Plastic Rabbit
- 2,859
- 4
- 25
- 27
1
vote
1 answer
how to use domains properly in nodejs
I try to use domains core module instead of process.on('uncaughtException'), to catch error
function setupDomains(req, res, next) {
var reqd = domain.create();
reqd.add(req);
reqd.add(res);
reqd.on('error', function(err) {
…

williamC
- 176
- 2
- 12
1
vote
1 answer
Why domains does not catch below exception?
Why domain does not handle below error?
var globalDomain = domain.createDomain();
globalDomain.run( function() {
// Why below exception does not get handled by globalDomain?
throw "some error";
});
globalDomain.on('error', function(msg)…

SunnyShah
- 28,934
- 30
- 90
- 137
0
votes
1 answer
Is it possible request angular server in nodejs server
I have two servers running now, one is NodeJS, the other is Angular.
NodeJS listens port 3000, angular listens port 8000. Is it possible to get angular website and then update at port 3000?
For example, users can open localhost:8000 to access my…

Yannan HE
- 15
- 2