The util.deprecate() method wraps fn (that may be a function or class) in such a way that it is marketed as a deprecated method. The util.deprecate() method returns a function that emits a DeprecationWarning. This warning is printed to the stderr when the function is called the first time. The function is called without any warning once the warning is emitted.
util.deprecate( fn, msg, [code] )
The parameters are defined below:
Create a file named "deprecate.js" and copy the following code snippet. After creating the file, use the command "node deprecate.js" to run this code.
const util = require('util'); var deprecateFunction = util.deprecate( // Defining the deprecated function function () { }, // Msg printed for deprecation "Warning: This method is deprecated !", // Deprecated API 'Deprication API' ); // Function call deprecateFunction();
C:\home\node>> node deprecate.js (node:153883) [Deprication API] DeprecationWarning: Warning: This method is deprecated !
const util = require('util'); function fun() { console.log("Welcome to Tutorials Point"); } var msg = 'This function is deprecated' var code = 'DEP0001'; var deprecateFunction = util.deprecate(fun, msg, code); // Function call deprecateFunction();
C:\home\node>> node deprecate.js Welcome to Tutorials Point (node:157003) [DEP0001] DeprecationWarning: This function is deprecated