Nnodejs

nodejs/timers-deprecations

Migrate deprecated node:timers APIs to public timer functions.

migrationtimers
Public
0 executions
0 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

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.