- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 快速入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 快速入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用工具模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - os.totalmem() 方法
Node.js 的os 模組提供了一組與作業系統相關的實用方法和屬性。
os 模組的Node.js os.totalmem() 方法返回系統總記憶體量,以整數形式表示的位元組數。
語法
以下是Node.js os.totalmem() 方法的語法:
os.totalmem()
引數
此方法不接受任何引數。
返回值
此方法返回系統總記憶體量(以位元組為單位)的整數。
以下示例演示了 os 模組中 Node.js os.totalmem() 方法的用法。
示例
在以下示例中,我們匯入 os 模組並嘗試透過將Node.js os.totalmem() 方法記錄到控制檯來列印當前系統的總記憶體。
const os = require('os');
console.log(os.totalmem());
輸出
134948720640
注意 - 為了獲得準確的結果,最好在本地執行以上程式碼。
執行上述程式後,os.totalmem() 方法將返回當前系統總 RAM 記憶體(以位元組為單位)。
16822587392
示例
在以下示例中,我們將系統總記憶體量從位元組轉換為 KB(千位元組)、MB(兆位元組)和 GB(吉位元組)。
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");
輸出
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
注意 - 為了獲得準確的結果,最好在本地執行以上程式碼。
如果我們編譯並執行上述程式,我們將列印系統總 RAM 記憶體(以位元組、千位元組 (KB)、兆位元組 (MB) 和吉位元組 (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
示例
在以下示例中,我們嘗試將系統總記憶體和可用系統記憶體從位元組轉換為 KB(千位元組)、MB(兆位元組)和 GB(吉位元組)。
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");
輸出
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
注意 - 為了獲得準確的結果,最好在本地執行以上程式碼。
執行上述程式後,我們將列印系統總 RAM 記憶體和可用 RAM 記憶體(以位元組、千位元組 (KB)、兆位元組 (MB) 和吉位元組 (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
nodejs_os_module.htm
廣告
