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

Published March 25, 2021

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();
  • 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();

That's all! 😃

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter