Fails with piping
Opened this issue · 1 comments
dandv commented
$ node script.js | tee script.log
^Cevents.js:163
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at exports._errnoException (util.js:1050:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:814:14)
The script is:
var ON_DEATH = require('death'); //this is intentionally ugly
ON_DEATH(function(signal, err) { console.log('croak'); })
setTimeout(function () {}, 10000);
node-cleanup doesn't call my handler either, but at least doesn't display this ugly error message :)
LuKks commented
You can use my package, it's more flexible because you have to set what you want to handle and I made it with Docker, PM2, etc in mind.
https://github.com/LuKks/like-process
const like = require('like-process');
like.on('cleanup', () => {
console.log('croak');
});
like.handle('exit');
setTimeout(function () {}, 10000);
Depending on the use, you should handle more events like uncaughtException
:
like.handle(['uncaughtException', 'unhandledRejection', 'exit']);
I'm very available if you have any problem with like-process
, I know this issue is extremely old but it's never late for new people that are having the same issue.