Ced
Ced

Reputation: 711

How to know the total amount of RAM of a computer?

I want to have basic stats about the computer running my app, in order to adjust several things depending of that result. Is there a way to know that info? is there a npm package I can use?

Upvotes: 2

Views: 2815

Answers (3)

AlexHalkin
AlexHalkin

Reputation: 1127

Just want to note that macOS's "free" and "available" memory is not the same. If you want to access available memory instead of free, you may try the package osx-extra.

https://www.npmjs.com/package/osx-extra

const osX = require("osx-extra");

const freeMem = osX.freemem();

this package provides freemem() method that returns the actual available memory for macOS and fallbacks to the same freemem() methods from node:os core module for all other operating systems.

Upvotes: 0

Pinaki
Pinaki

Reputation: 1040

index.ts

import os from 'os';

console.log('RAM: ', os.totalmem());
console.log('Free RAM: ', os.freemem());

output -

RAM:  8496254976
Free RAM:  1699966976

Upvotes: 1

danilodeveloper
danilodeveloper

Reputation: 3880

With Node.js OS package you can do this and much more.
Take a look in os.freemem or os.totalmem

From Node.js documentation:

os.freemem()

Returns the amount of free system memory in bytes.

os.totalmem()

Returns the total amount of system memory in bytes.

Upvotes: 8

Related Questions