- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js - os.uptime() Method
The os module of Node.js provides a bunch of operating system-related utility methods and properties.
The Node.js os.uptime() method returns an integer that has the system uptime in number of milliseconds. The value returned by this method will be bigger than zero if the process is running, and will be equal to zero if it's not running or hasn't been initialized yet.
Syntax
Following is the syntax of the Node.js os.uptime() method −
os.uptime()
Parameters
This method does not accept any parameters.
Return value
This method returns an integer value that represents the system uptime in number of seconds.
Example
In the following example, we are trying to import the os module and return the uptime of the current system.
const os = require('os'); console.log(os.uptime());
Output
After executing the above program, the os.uptime() method will return the system running time in seconds.
35966
Example
In the following example, we tried to print the uptime of the current system in seconds, minutes, hours, and days.
const os = require('os'); var Hours = os.uptime()/(60*60); console.log('Up time in (Seconds): '+ os.uptime() + ' Seconds'); console.log('Up time in (Minutes): '+ os.uptime()/60 + ' Minutes'); console.log('Up time in (Hours): '+ Hours + ' Hours'); var days = Hours/(24); console.log('Up time in (Days): '+ days + ' Days');
Output
After executing the above program, we printed the system's running time in seconds, minutes, hours, and days.
Up time in (Seconds): 35936 Seconds Up time in (Minutes): 598.9333333333333 Minutes Up time in (Hours): 9.982222222222223 Hours Up time in (Days): 0.415925925925926 Days