Node.js - process.traceDeprecation() 方法


This process.traceDeprecation() 方法说明了当前 Node.js 项目上是否设置了 --trace-deprecation 标志。此布尔标志控制着是否打印弃用警告消息的跟踪。

语法

process.traceDeprecation( )

示例 1

创建名为 "traceDeprecation.js" 的文件并复制代码段。创建文件后,使用命令 "node traceDeprecation.js" 来运行此代码,如下所示 −

// process.traceDeprecation() Demo Example

// Importing the process module
const process = require('process');

// Printing traceDeprecation default value
console.log(process.traceDeprecation);

输出 1

C:\home
ode>> node traceDeprecation.js undefined

输出 2

C:\home
ode>> node --trace-deprecation traceDeprecation.js true

示例 2

// process.traceDeprecation() Demo Example

// Importing the process module
const process = require('process');

// Initializing the traceDeprecation flag
process.traceDeprecation = false;

// Printing traceDeprecation
console.log(process.traceDeprecation);

// Initializing the traceDeprecation flag
process.traceDeprecation = true;

// Printing traceDeprecation
console.log(process.traceDeprecation);

输出 1

C:\home
ode>> node traceDeprecation.js false true

输出 2

C:\home
ode>> node --trace-deprecation traceDeprecation.js true true

更新日期: 17-Jan-2022

2K+ 浏览量

开启你的 职业生涯

通过完成课程获得认证

立刻开始
广告
© . All rights reserved.