os.freemem()

Returns the amount of free system memory in bytes.

Since Node 0.3 Spec ↗

Syntax

os.freemem()

Returns

number — Free physical memory in bytes.

Examples

import { freemem } from 'node:os';

console.log(Math.round(freemem() / 1024 / 1024), 'MB free');
Output
4096 MB free
import { freemem } from 'node:os';

if (freemem() < 200 * 1024 * 1024) {
  console.warn('low memory');
}
Output
low memory

Notes

This is an OS-level snapshot and fluctuates constantly; the OS may use seemingly "used" memory for caches that are reclaimable. Not a reliable signal of process health on its own.

See also