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.