Skip to content
Related Articles

Related Articles

Node.js process.report Object

View Discussion
Improve Article
Save Article
  • Last Updated : 25 May, 2022
View Discussion
Improve Article
Save Article

The process.report is an object found under the Process Module of Node.js. process.report have many methods such as ‘writeReport’, ‘getReport’, ‘directory’, ‘filename’, ‘compact’, ‘signal’, ‘reportOnFatalError’, ‘reportOnSignal’, and ‘reportOnUncaughtException’. These methods are used to generate diagnostic reports for the current process.

Syntax:

process.report

OR

process.report.methodName

Where the methodName can be any of the above-mentioned methods.

Return Value: ‘process.report’ returns an object, containing all of the above-mentioned methods.

Example:

Javascript




const process = require('process');
const report = process.report;
console.log(reports);

Output:

 

Methods of process.report:

1. compact: This method returns the compact status.

Javascript




const process = require('process');
const compactData = process.report.compact;
if(compactData){
    console.log(compactData);
}
else{
    console.log("Compact Status is false: No data to show");
}

Output:

 

2. writeReport: This method is used to write a report on a particular file, file pass is passed as the parameter inside the ‘writeReport’ function. 

Javascript




const process = require('process');
const report = process.report;
console.log(report.writeReport("./Geeks/geek.txt"));

Output:

 

3. directory: This method returns the directory where the report is written. The default value is the empty string which means that the report is written in the current directory.

Javascript




const process = require('process');
const report = process.report;
  
if (report.directory) {
    console.log("Report is written in the
        given directory: " + report.directory);
} else {
    console.log("Report is written in current directory");
}

Output:

 

4. filename: This method returns the filename where the report is written. The default value is the empty string which means that the report is written in the current file.

Javascript




const process = require('process');
const report = process.report;
console.log(report.filename);

Output:

 

5. getReport: This method is used to generate a report for the currently running process.

Javascript




const process = require('process');
const report = process.report;
console.log(report.getReport());

Output:

 

From the report we can also access any particular field: Let’s access the current working directory, which is in the header of the generated report.

Javascript




const process = require('process');
const report = process.report;
console.log(report.getReport().header.cwd);

Output:

 

6. signal: This method returns the signal which is used to generate the diagnostic report. The default value is ‘SIGUSR2’.

Javascript




const process = require('process');
const report = process.report;
console.log(report.signal);

Output:

 

7. reportOnFatalError: This method returns the boolean false if there is no fatal error, otherwise it will return true if there is a fatal error such as out of memory error or failed C++ assertions.

Javascript




const process = require('process');
const report = process.report;
  
if (report.reportOnFatalError) {
    console.log("Fatal error found");
} else {
    console.log("No Fatal Errors");
}

Output:

 

8. reportOnSignal: This method return the boolean false by default, and if true, a diagnostic report is generated when the process receives the signal specified by the process.report.signal.

Javascript




const process = require('process');
const report = process.report;
console.log(report.reportOnSignal);

Output:

 

9. reportOnUncaughtException: This method return the boolean false by default, and if true, then it means there are some uncaught exceptions and a diagnostic report is generated.

Javascript




const process = require('process');
const report = process.report;
  
if (report.reportOnUncaughtException) {
    console.log("Uncaught Exception");
} else {
    console.log("No Uncaught Exception");
}

Output:

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!