- 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 - Streams
- Node.js - 文件系统
- Node.js MySQL
- Node.js - MySQL 快速入门
- Node.js - MySQL创建数据库
- Node.js - MySQL创建表
- 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 快速入门
- Node.js - MongoDB 创建数据库
- Node.js - MongoDB 创建集合
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB 查询
- Node.js - MongoDB 排序
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js模块
- Node.js - 模块
- Node.js - 内置模块
- Node.js - utility 模块
- Node.js - Web 模块
Node.js - os.totalmem() 方法
Node.js 的 os 模块提供了一堆与操作系统相关的实用方法和属性。
Node.js os 模块的 os.totalmem() 方法以整数形式以字节数的形式返回系统内存总量。
语法
以下是Node.js os.totalmem()方法的语法 -
os.totalmem()
参数
此方法不接受任何参数。
返回值
此方法以整数形式返回系统内存总量(以字节为单位)。
以下示例演示了 os 模块Node.js os.totalmem() 方法的用法。
例在以下示例中,我们将导入 os 模块并尝试通过将 os.totalmem() 方法记录到控制台来打印当前系统总内存Node.js。
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
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
注意 −为了获得准确的结果,最好在本地执行上述代码。
如果我们编译并运行上述程序,我们将以字节、千字节 (KB)、兆字节 (MB) 和千兆字节 (GB) 为单位打印整个系统的 RAM 内存。
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 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
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
注意 - 为了获得准确的结果,最好在本地执行上述代码。
执行上述程序后,我们以字节、千字节 (KB)、兆字节 (MB) 和千兆字节 (GB) 为单位打印了总和空闲系统的 RAM 内存。
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
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