os.totalmem()

Returns the total amount of system memory in bytes.

Since Node 0.3 Spec ↗

Syntax

os.totalmem()

Returns

number — Total physical memory in bytes.

Examples

import { totalmem } from 'node:os';

console.log((totalmem() / 1024 ** 3).toFixed(1), 'GB');
Output
16.0 GB
import { totalmem, freemem } from 'node:os';

const usedPct = (1 - freemem() / totalmem()) * 100;
console.log(usedPct.toFixed(0) + '% used');
Output
62% used

Notes

Reports host physical memory, not container/cgroup limits, so it can overstate available memory in Docker. For the process heap use `process.memoryUsage()`.

See also