A process object is a global object, so it can be accessed from anywhere. As it is a predefined library, so we don’t have to download it to our system globally.
Prerequisites:
- Basic knowledge of Node
- Node.js installed (version 12+)
- NPM installed (version 6+)
Requiring Module: You can include the module using the following code:
var process = require('process');
Note: It’s a global object, so no need to install it explicitly.
Example 1: Create a JavaScript file index.js and write down the following code:
index.js
var process = require( 'process' );
console.log( 'this is the working directory --> ' + process.cwd());
console.log( 'this is the process version --> ' + process.version);
console.log( 'current OS we are using --> ' + process.platform);
|
Run the index.js file using the following command:
node index.js
Output:
Example 2: Create a JavaScript file index.js and write down the following code:
index.js
var process = require( 'process' );
console.log( 'Feature Property: ' , process.features);
|
Run the index.js file using the following command:
node index.js
Output:
Feature Property: {
inspector: true,
debug: false,
uv: true,
ipv6: true,
tls_alpn: true,
tls_sni: true,
tls_ocsp: true,
tls: true,
cached_builtins: true
}
Reference: https://nodejs.org/api/process.html#process_process
Last Updated :
31 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...