Post

NodeJS memory usage check

NodeJS

Checking memory usage

1
2
3
4
5
6
7
8
9
10
11
12
13
const makeReadable = (value: number): string =>
  `${Math.round((value / 1024 / 1024) * 100) / 100} MB`;

export const memoryUsage = (): string => {
  const used = process.memoryUsage();

  let usage = 'Memory usage >> ';
  for (const [key, value] of Object.entries(used)) {
    usage += `${key}: ${makeReadable(value)}, `;
  }

  return usage;
};
This post is licensed under CC BY 4.0 by the author.