- 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.totalmem() Method
The os module of Node.js provides a bunch of operating system-related utility methods and properties.
The Node.js os.totalmem() method of os module returns the total amount of system memory as a number of bytes in integer form.
Syntax
Following is the syntax of the Node.js os.totalmem() method −
os.totalmem()
Parameters
This method does not accept any parameters.
Return value
This method returns the total amount of system memory in bytes as an integer.
The below examples demonstrate the usage of Node.js os.totalmem() method of os module.
Example
In the following example, we are importing the os module and trying to print the total current system memory by logging Node.js os.totalmem() method to the console.
const os = require('os'); console.log(os.totalmem());
Output
134948720640
Note − To get the accurate result, better execute the above code in local.
After executing the above program, the os.totalmem() method will return the current system's total RAM memory in bytes.
16822587392
Example
In the following example, we are converting the amount of total system memory from bytes to KB(Kilobyte), MB(Megabyte), and GB(Gigabyte).
const os = require('os'); var tot_mem_in_bytes = os.totalmem(); var tot_mem_in_kb = Math.floor(os.totalmem()/(1024)); var tot_mem_in_mb = Math.floor(os.totalmem()/(1024*1024)); var tot_mem_in_gb = Math.floor(os.totalmem()/(1024*1024*1024)); console.log("The amount of total current system memory (in bytes): " + tot_mem_in_bytes + " Bytes"); console.log("The amount of total current system memory (in KB): " + tot_mem_in_kb + " KB"); console.log("The amount of total current system memory (in MB): " + tot_mem_in_mb + " MB"); console.log("The amount of total current system memory (in GB): " + tot_mem_in_gb + " GB");
Output
The amount of total current system memory (in bytes): 134948720640 Bytes The amount of total current system memory (in KB): 131785860 KB The amount of total current system memory (in MB): 128697 MB The amount of total current system memory (in GB): 125 GB
Note − To get the accurate result, better execute the above code in local.
If we compile and run the above program, we printed the total system's RAM memory in bytes, kilobytes(KB), Megabytes(MB), and Gigabytes(GB).
The amount of total current system memory (in bytes): 16822587392 Bytes The amount of total current system memory (in KB): 16428308 KB The amount of total current system memory (in MB): 16043 MB The amount of total current system memory (in GB): 15 GB
Example
In the following example, we are trying the amount of total system memory and free system memory from bytes to KB(Kilobyte), MB(Megabyte), and GB(Gigabyte).
const os = require('os'); var tot_mem_in_bytes = os.totalmem(); var tot_mem_in_kb = Math.floor(os.totalmem()/(1024)); var tot_mem_in_mb = Math.floor(os.totalmem()/(1024*1024)); var tot_mem_in_gb = Math.floor(os.totalmem()/(1024*1024*1024)); var mem_in_bytes = os.freemem(); var mem_in_kb = Math.floor(os.freemem()/(1024)); var mem_in_mb = Math.floor(os.freemem()/(1024*1024)); var mem_in_gb = Math.floor(os.freemem()/(1024*1024*1024)); console.log("The amount of total current system memory (in bytes): " + tot_mem_in_bytes + " Bytes"); console.log("The amount of total current system memory (in KB): " + tot_mem_in_kb + " KB"); console.log("The amount of total current system memory (in MB): " + tot_mem_in_mb + " MB"); console.log("The amount of total current system memory (in GB): " + tot_mem_in_gb + " GB"); console.log('----------------------------------------------------------------------------'); console.log("The amount of free current system memory (in bytes): " + mem_in_bytes + " Bytes"); console.log("The amount of free current system memory (in KB): " + mem_in_kb + " KB"); console.log("The amount of free current system memory (in MB): " + mem_in_mb + " MB"); console.log("The amount of free current system memory (in GB): " + mem_in_gb + " GB");
Output
The amount of total current system memory (in bytes): 134948720640 Bytes The amount of total current system memory (in KB): 131785860 KB The amount of total current system memory (in MB): 128697 MB The amount of total current system memory (in GB): 125 GB ----------------------------------------------------------------------- The amount of free current system memory (in bytes): 130385920000 Bytes The amount of free current system memory (in KB): 127330000 KB The amount of free current system memory (in MB): 124345 MB The amount of free current system memory (in GB): 121 GB
Note − To get the accurate result, better execute the above code in local.
After executing the above program, we printed the total and free system's RAM memory in bytes, kilobytes(KB), Megabytes(MB), and Gigabytes(GB).
The amount of total current system memory (in bytes): 16822587392 Bytes The amount of total current system memory (in KB): 16428308 KB The amount of total current system memory (in MB): 16043 MB The amount of total current system memory (in GB): 15 GB ---------------------------------------------------------------------------- The amount of free current system memory (in bytes): 8955355136 Bytes The amount of free current system memory (in KB): 8745464 KB The amount of free current system memory (in MB): 8540 MB The amount of free current system memory (in GB): 8 GB