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
21
votes
5 answers
How to use Node.js 0.8.x domains with express?
How can I create Express/Connect middleware which wrap each request in its own domain?

Rafał Sobota
- 1,468
- 1
- 17
- 32
19
votes
3 answers
What is the difference between local and global module in Node.js? When to use local and global module?
We can access local module using require function but cannot access global module through it.
I read somewhere that to use global module we need to make it local then import it through require function.
So if we cannot access global module…

Badal
- 376
- 4
- 11
15
votes
5 answers
Unable to handle exception with node.js domains using express
I want to use Node.js Domains to catch exceptions. It is working so far, but there is one place I can't get domains to catch the exception. exception2 in the callback is caught and handled in the domain.on('error') handler, but exception1 is not…

user1007983
- 191
- 1
- 8
10
votes
2 answers
Node, Express, domains, uncaught exceptions - still lost
I have been reading for hours on exception handling in Node. I understand the cons of using uncaughtException, I understand that shutting down the process is good for preventing any "unknown state" where "anything can happen". I understand that…

Ryan Wheale
- 26,022
- 8
- 76
- 96
7
votes
4 answers
Nodejs error handling with domains and socket.io
I'm just starting using domains in nodejs for error management.
There's something I cant understand when I use them with socket.io.
That's my example code:
io.sockets.on('connection', function cb1(socket){
socket.on('event', function cb2(data){
…

dorexx45
- 71
- 1
- 2
6
votes
1 answer
How nodejs domains actually work behind the scenes for multiple requests?
My use case requires node.js domains to share information across server files at a request level.
Sample Implementation in express.js
domain = require('domain');
app.use(function(req, res, next) {
var reqDomain = domain.create();
…

keshav
- 734
- 6
- 19
4
votes
0 answers
node.js / io.js - How can I consistently log a request's flow considering domains are being deprecated?
I've been using domains to add a request id to my logs.
This is very convenient because it means I don't have to pass my request object everywhere, but I can still see the request context that a db query ran in, and I can follow the process each…

AvnerSo
- 1,609
- 1
- 16
- 23
4
votes
1 answer
Can domains be nested in node.js?
With synchronous errors, you can nest error scopes like this:
try {
try {
throw Error('e')
} catch(e) {
if(e.message !== 'f')
throw e
}
} catch(e) {
handleError(e)
}
This is how I would expect it to work, but it doesn't (seems…

B T
- 57,525
- 34
- 189
- 207
4
votes
2 answers
Domains not properly catching errors while testing nodeJS in mocha
When running tests that utilize domains for error handling, Mocha still appears to be throwing an error even if a domain handler inside a library should have caught the error. If I execute the code outside of Mocha, it functions correctly leading me…

Owen Allen
- 11,348
- 9
- 51
- 63
4
votes
1 answer
How to do proper error handling in node with domain?
I am using a third party library. Which is using node domain for error handling.
If the callback function passed to that third party library have any error, It end-up in calling my callback multiple times.
Example code is:
var startFunction =…

Vivek Goel
- 22,942
- 29
- 114
- 186
4
votes
0 answers
NodeJS domains module doesn't exit cleanly
I've been experimenting with domains in node JS. The code does what I expect it to, but when the code has completed, node doesn't exit cleanly, which makes me think there's some uncollected garbage or something that I don't understand. Any…

Dave Cleal
- 41
- 1
4
votes
1 answer
Unable to call dispose on domain at appropriate time
I'm having an issue with the domain module. Currently, I'm trying to catch any uncaught errors that are thrown in a request. Using an express middleware and domains. All requests are routed through this function before calling next and moving on to…

Trevor
- 11,269
- 2
- 33
- 40
3
votes
1 answer
Express.js 4 and domain module: why domain doesn't handle the error?
I'm trying to familiarize myself with domain module. So, I created a study sample below:
var express = require('express')
var domain = require('domain')
var supertest = require('supertest')
describe('some', function() {
it('some',…

kharandziuk
- 12,020
- 17
- 63
- 121
3
votes
2 answers
Node.js domain cluster worker disconnect
Looking at the example given at the nodejs domain doc page: http://nodejs.org/api/domain.html, the recommended way to restart a worker using cluster is to call first disconnect in the worker part, and listen to the disconnect event in the master…

Ervadac
- 936
- 3
- 9
- 26
3
votes
1 answer
Do node.js domains automatically clean themselves up or do I have to call domain.dispose()
I'm a bit confused about node.js domains. I'm using them to catch errors that may be thrown in asynchronous code.
I'm not sure though, whether or not domains automatically clean themselves up for garbage collection once the domain.run(blah) has…

balupton
- 47,113
- 32
- 131
- 182