Hemanth's Scribes

node

Method Deprecated Warning in Node.js

Author Photo

Hemanth HM

Thumbnail

Warn users on deprecated methods using the util module.

#!/usr/bin/env node
// __filename = hello.js

util = require('util');

exports.yo = function() {
  console.log("yo yo!");
};

exports.hello = util.deprecate(function() {
  return exports.yo();
}, '`hello` is deprecated, please use `yo` instead.');

## Usage
javascript
> greet = require("hello");
{ yo: [Function], hello: [Function: deprecated] }

> greet.hello()
`hello` is deprecated, please use `yo` instead.
yo yo!

Happy hacking!

#node#javascript
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.