DEV Community

Cover image for How to get the total memory of a system using Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to get the total memory of a system using Node.js?

Originally posted here!

To get the total memory space, you can use the totalmem() method from the os module in Node.js.

/* Get total memory space in Node.js */

// import os module
const os = require("os");

// check the total memory
const totalMemory = os.totalmem();
Enter fullscreen mode Exit fullscreen mode
  • The method returns the total memory in bytes as integers.

See the above code live in repl.it.

You can also get the free memory available to use using the freemem() method from the os module like this,

const os = require("os");

// check free memory
const freeMemory = os.freemem();
// check the total memory
const totalMemory = os.totalmem();
Enter fullscreen mode Exit fullscreen mode

That's all! 😃

Feel free to share if you found this useful 😃.


Top comments (1)

Collapse
 
fridaycandours profile image
Friday candour

very useful thanks! tired to read the docs, chatgpt is garbage.