Node.js Process Object
In Node.js, the process object is a powerful global utility that gives access to information about the running application ÔÇö process ID, architecture, platform, Node.js version, uptime, memory usage, and more. It can also perform actions like killing a process and handling signals. Since it is global and an instance of EventEmitter, it can be accessed anywhere.
Node.js Tutorial:-
Complete Python Course:-
Common process Properties
archÔÇö processor architecture (arm, ia32, x64)argvÔÇö command-line arguments arrayenvÔÇö environment variablespidÔÇö process IDplatformÔÇö darwin, linux, win32, etc.version/versionsÔÇö Node.js and dependency versions
Example 1: Basic Process Properties
// process_example1.js
console.log(`Architecture: ${process.arch}`);
console.log(`PID: ${process.pid}`);
console.log(`Platform: ${process.platform}`);
console.log(`Version: ${process.version}`);
Example 2: Command-Line Arguments
// process_example2.js
process.argv.forEach((value, index) => {
console.log(`${index}: ${value}`);
});
Node.js itself is the first argument, the file name is the second, and extra arguments follow.
Useful process Functions
cwd()ÔÇö current working directoryhrtime()ÔÇö high-resolution time [seconds, nanoseconds]memoryUsage()ÔÇö memory usage detailskill(pid[, signal])ÔÇö kill a process by PIDuptime()ÔÇö process uptime in seconds
// process_example3.js
console.log(`Current directory: ${process.cwd()}`);
console.log(`Uptime: ${process.uptime()} seconds`);
Handling Process Events
process.on('exit', (code) => {
console.log(`Process exiting with code: ${code}`);
});
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Conclusion
The process object is essential for accessing runtime information and controlling the application lifecycle in Node.js. From reading arguments to handling exit events, it is a core tool every Node developer should know. For more tutorials, stay connected with .
node js process model
node js process exit gracefully
node process exit
process.on uncaughtexception
process.exit(1) in node js
node js process example
node js process argv
node js process w3schools