Node.js process.uptime() Method
The process.uptime() method is an inbuilt application programming interface of the process module which is used to get the number of seconds the Node.js process is running.
Syntax:
process.uptime();
Parameters: This method does not accept any parameter.
Return Value: It returns a floating-point number specifying the number of seconds the Node.js process is running.
Below examples illustrate the use of process.uptime() method in Node.js:
Example 1:
const process = require( 'process' );
console.log(process.uptime());
|
Output:
0.0842063
Example 2:
const process = require( 'process' );
if (process.uptime) {
console.log( "The number of seconds the"
+ " Node.js process is running: "
+ process.uptime() + " seconds" );
var i = 1000000;
while (i--);
console.log( "The number of seconds the"
+ " Node.js process is running: "
+ process.uptime() + " seconds" );
console.log( "In whole seconds: "
+ Math.floor(process.uptime())
+ " seconds" );
}
|
Output:
the number of seconds the Node.js process is running: 0.077 seconds
the number of seconds the Node.js process is running: 0.087 seconds
In whole seconds: 0 seconds
Note: The above program will compile and run by using the node filename.js
command.
Reference: https://nodejs.org/api/process.html#process_process_uptime
Last Updated :
11 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...