const util = require('util');
// Original function
function oldFunction(x, y) {
return x + y;
}
// Deprecate the function
const deprecatedFunction = util.deprecate(
oldFunction,
'oldFunction() is deprecated. Use newFunction() instead.',
'DEP0001'
);
// New function
function newFunction(x, y) {
return x + y;
}
// Using the deprecated function will show a warning
console.log('Result:', deprecatedFunction(5, 10));
// Using the new function
console.log('Result:', newFunction(5, 10));
Result: 15 Result: 15 (node:16996) [DEP0001] DeprecationWarning: oldFunction() is deprecated. Use newFunction() instead. (Use `node --trace-deprecation ...` to show where the warning was created)