Check computer RAM size with Node.js

Last updated on March 20, 2021 A Goodman Loading... Post a comment

The built-in os module in Node provides methods that help you check your memory size.

const os = require("os");

// Get the number of total memory in Byte
const totalRAM = os.totalmem();
// Print the result in MB
console.log(totalRAM / 1024 / 1024);

// Get the number of available memory in Byte
const freeRAM = os.freemem();
// Print the result in MB
console.log(freeRAM / 1024 / 1024);

Note that 1 MB = 1024 KBs and 1KB = 1024 byte.

Related Articles

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x