Node is running but you don't know why? why-is-node-running is here to help you.
This is a cheeky module that plays with process.binding of node, specifically with process.binding('contextify').ContextifyScript; the core of this library is from node's source.
GET IT:npm install --save why-is-node-running
Sample usage:
123456789101112131415
varlog=require('why-is-node-running');// should be your first require varnet=require('net');functioncreateServer(){varserver=net.createServer();setInterval(function(){},1000);server.listen(0);}createServer();createServer();setTimeout(function(){log()// logs out active handles that are keeping node running },100);
When executed in /tmp you see an output like:
1234567891011121314151617
There are 4 known handle(s) keeping the process running and 0 unknown
Known handles:
# Timer/private/tmp/l:6 - setInterval(function(){}, 1000);
/private/tmp/l:10 - createServer();
# TCP/private/tmp/l:7 - server.listen(0);
/private/tmp/l:10 - createServer();
# TCP/private/tmp/l:7 - server.listen(0);
/private/tmp/l:11 - createServer();
# Timer/private/tmp/l:13 - setTimeout(function(){