25

Why is domain API deprecated in Node.js?

I found it handy to catch errors in context of a incoming web request rather than exception boiling up to the level of process.

Also, is there any alternative to domain APIs that can be now be used?

prasun
  • 7,073
  • 9
  • 41
  • 59

2 Answers2

19

Node.js issue #66: deprecate domains:

The problem isn't the user experience of domains, as you say the API is simple and users are generally happy with it, but the consequences domains have in maintenance and complications for the node.js core code – that seemingly simple API impacts all of the code base in a too negative way.

Domains in its current form must go. That's certain. What the alternative is, no one knows.

I don't get how we can deprecate something that covers a use case that cannot be covered otherwise, without providing clear (and ready) alternatives.

If we flip that the other way around. We know domains must go, and will have to be removed at some point soon-ish. Would you prefer there be no indication of this?

The linked issue also mentions (the lack of) alternatives.

ax.
  • 58,560
  • 8
  • 81
  • 72
  • They at the very least should make it a node module so it can be plugged in. – Nick Nov 16 '15 at 23:20
  • 4
    domains are an essential feature of node.js core and deprecating them is a bad idea because it is doubtful any alternative can implemented in a different way; so any alternative will be no more maintenable than domains as they are now. – Alexander Mills Feb 22 '16 at 07:47
6

zone.js is mentioned as an alternative in another similar question. Angular2 uses it heavily. (I have no personal experience with zone.js in Node.js.)

Gábor Imre
  • 5,899
  • 2
  • 35
  • 48