The process
module has a wealth of information about the running process and the system architecture. This information can be useful when you’re implementing applications. For example, the process.pid
property gives you the process ID that you can then have your application use.
Table 9.3 lists the properties and methods that you can access from the process
module and describes what they return.
To help you understand accessing information using the process
module, the code in Listing 9.1 makes a series of calls, and it outputs the results to the console, as shown in Figure 9.1.
01 var util = require('util'),
02 console.log('Current directory: ' + process.cwd());
03 console.log('Environment Settings: ' + JSON.stringify(process.env));
04 console.log('Node Args: ' + process.argv);
05 console.log('Execution Path: ' + process.execPath);
06 console.log('Execution Args: ' + JSON.stringify(process.execArgv));
07 console.log('Node Version: ' + process.version);
08 console.log('Module Versions: ' + JSON.stringify(process.versions));
09 //console.log(process.config);
10 console.log('Process ID: ' + process.pid);
11 console.log('Process Title: ' + process.title);
12 console.log('Process Platform: ' + process.platform);
13 console.log('Process Architecture: ' + process.arch);
14 console.log('Memory Usage: ' + util.inspect(process.memoryUsage()));
15 var start = process.hrtime();
16 setTimeout(function() {
17 var delta = process.hrtime(start);
18 console.log('High-Res timer took %d seconds and %d nanoseconds',
19 delta[0], + delta[1]);
20 console.log('Node has been running %d seconds', process.uptime());
21 }, 1000);