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
asintegers
.
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! 😃