Node's global object process
has a really cool helper function called memoryUsage()
that helps measure (you guessed it) memory usage.
Some of the below code is taken and modified from Valentino Gagliardi's blog article on inspecting memory usage in Node.js.
const MB_DIVISOR = 1_000_000
const memoryUsage = process.memoryUsage()