unref() and ref()

Methods on Node.js timers, sockets and servers: unref() lets the process exit even though this handle is still active, and ref() undoes that.

In more detail

They suit background work such as heartbeats or a shutdown fail-safe timer, which should never on their own keep a finished program running. They return the object itself, so a call can be chained, as in setTimeout(fn, 10_000).unref().

Related terms

Taught in

References