Nnodejs

nodejs/timers-deprecations

Migrate deprecated node:timers APIs to public timer functions.

migrationtimers
Public
14 executions
Run locally
npx codemod @nodejs/timers-deprecations
Documentation

Node.js Timers Deprecations

This recipe migrates deprecated internals from node:timers to the supported public timers API. It replaces usages of timers.enroll(), timers.unenroll(), timers.active(), and timers._unrefActive() with standard constructs built on top of setTimeout(), clearTimeout(), and Timer#unref().

See the upstream notices: DEP0095, DEP0096, DEP0126, and DEP0127.

Example

Replace timers.enroll()

diff

Replace timers.unenroll()

diff

Replace timers.active() and timers._unrefActive()

diff

Caveats

The legacy APIs exposed internal timer bookkeeping fields such as _idleStart or _idleTimeout. Those internals have no public equivalent. The codemod focuses on migrating the control flow to modern timers and leaves application specific bookkeeping to the developer. Carefully review the transformed code to ensure that any custom metadata is still updated as expected.

Ready to contribute?

Build your own codemod and share it with the community.