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:
javascript
Output:
javascript
Output:
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:
// Node.js program to demonstrate the
// process.uptime() Method
// Allocating process module
const process = require('process');
// Printing the number of seconds
// the Node.js process is running
console.log(process.uptime());
0.0842063Example 2:
// Node.js program to demonstrate the
// process.uptime() Method
// Allocating process module
const process = require('process');
// Checking whether the method
// exists or not
if (process.uptime) {
// Printing uptime() value
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");
}
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 secondsNote: The above program will compile and run by using the
node filename.js command.
Reference: https://nodejs.org/api/process.html#process_process_uptime