Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we find a list of deprecated methods that are currently in use in a Node JS project?

I want to replace all deprecated methods from some third-party packages in a Node JS project but I couldn’t find an easy way to list those methods. I have searched the Node JS CLI documentation but I couldn’t find the exact command to do that. Is there a command in Node JS CLI to actually do that? Or is there a standard practice to replace deprecated methods from a third-party library?

like image 762
Pablo Espantoso Avatar asked Nov 15 '25 22:11

Pablo Espantoso


1 Answers

Node.js has three types of deprecations: documentation-only, runtime, and end-of-life.

End-of-life deprecations are easy to "find" because they are basically things that have been removed and will cause errors when you try to use them.

Runtime deprecations are pretty easy to find because they emit warnings so if you have logging available, you will see them.

Documentation-only deprecations won't show up, but a good number of them become runtime deprecations if you run Node.js with the --pending-deprecation flag or the NODE_PENDING_DEPRECATION environment variable set.

It's also a good idea (in my opinion) to run with the --trace-warnings flag or the --trace-deprecation flag so that you get a stack trace for your deprecation warnings to find them easily in your dependencies, etc.

Two important limitations of --pending-deprecation:

  • It won't find deprecated APIs until you try to use them. Parsing is not enough. (Having 100% test coverage is useful.)
  • Not all (or even most) documentation-only APIs emit warnings with --pending-deprecation. However, this will cause warnings for many of the most important ones, so it's totally worth doing in my opinion.

If you want to always get notified of pending deprecations and have stack traces for all warnings, you can set two environment variables in your .profile or .bashrc or equivalent:

NODE_PENDING_DEPRECATION=1
NODE_OPTIONS=--trace-warnings

Be aware that this will make pretty much everything you run noisy. Even npm will start printing warnings on nearly every invocation.

like image 173
Trott Avatar answered Nov 17 '25 21:11

Trott