euthanasia
v2.0.1
Published
Gracefully exits a Node.js process when memory or CPU usage exceeds defined thresholds. Supports customizable exit logic via async hooks.
Readme
euthanasia
when your node.js process uses too much memory or cpu, allow it to gracefully exit
usage:
const euthanasia = require('euthanasia');
euthanasia({
memory: 100, // 100 MB limit
cpu: 80, // 80% CPU limit
interval: 10000, // check every 10 seconds
// called when either memory or CPU limit is exceeded
ready: async ({ memory, cpu }) => {
// your logic here
if (memory) {
console.log(`Memory limit exceeded: ${memory} MB`);
}
if (cpu) {
console.log(`CPU limit exceeded: ${cpu.toFixed(2)}%`);
}
// You can return false to skip exit (e.g., wait for cleanup)
return true;
}
});install:
npm i euthanasia --savelicense:
MIT
