Each Node.js script that runs is a process.
Useful process information includes:
Check Node.js Process Documentation for more.
The process.env property is an object that stores and controls information about the environment in which the process is currently running.
console.log(process.env)
{ SHELL: '/bin/bash',
USER: 'anna',
HOME: '/home/anna',
LOGNAME: 'anna',
...
}
We use the process.argv
property to access CLI arguments.
The first two elements are the node and the application’s name, while the rest are the command-line arguments.
node web.js testing app features
console.log(process.argv[2])
// Output: features
To exit a process, use the exit function:
process.exit()
process.memoryUsage() returns information on the CPU demands of the current process.
> process.memoryUsage()
//using process.memoryUsage() will return an object in the format:
{
rss: 22790144,
heapTotal: 6037504,
heapUsed: 3818032,
external: 1583000,
arrayBuffers: 9461
}