node:domain exports Domain, create(), createDomain(), and active from
Node’s deprecated domain. Synchronous and timer errors thrown inside run()
go to the domain’s error event. Use Promise and EventEmitter error handling in new code.
Example
// domain.mjs
import domain from "node:domain";
const d = domain.create();
d.on("error", (error) => console.log("caught:", error.message));
d.run(() => {
setTimeout(() => {
throw new Error("timer failed");
}, 1);
});elide run domain.mjs prints:
caught: timer failedReference
Status: Full · Not measured
domain exports
Domain, active, create, createDomain