Node.js - process.traceDeprecation() Method


This process.traceDeprecation() method states whether the --trace-deprecation flag is set or not on the current Node.js project. This Boolean flag controls whether the trace of deprecation warning messages are printed or not.

Syntax

process.traceDeprecation( )

Example 1

Create a file with the name "traceDeprecation.js" and copy the following code snippet. After creating the file, use the command "node traceDeprecation.js" to run this code as shown in the example below −

// process.traceDeprecation() Demo Example

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

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

Output 1

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

Output 2

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

Example 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);

Output 1

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

Output 2

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

Updated on: 17-Jan-2022

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements