Node.js process.throwDeprecation 属性
process.throwDeprecation 属性是 process 模块的内置应用程序编程接口,用于指示当前 Node.js 进程是否设置了 –throw-deprecation 标志。process.throwDeprecation 是可变的,因此运行时可能改变是否将不赞成使用警告转换为错误。
语法:
process.throwDeprecation
返回值: 此属性指示当前 Node.js 进程是否设置了 –throw-deprecation 标志。
下面的示例演示了在 Node.js 中使用 process.throwDeprecation 属性 :
示例1:
// Node.js program to demonstrate the
// process.throwDeprecation Property
// Include process module
const process = require('process');
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);
运行命令: node –throw-deprecation hello.js
输出1:
true
运行命令: node hello.js
输出2:
undefined
示例2:
// Node.js program to demonstrate the
// process.throwDeprecation Property
// Include process module
const process = require('process');
// Instance Properties
process.throwDeprecation = false;
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);
// Instance Properties
process.throwDeprecation = true;
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);
运行命令: node –throw-deprecation hello.js
输出 1:
true
true
运行命令: node hello.js
输出 2:
false
true
参考: https://nodejs.org/api/process.html#process_process_throwdeprecation