Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including why-is-node-running with all npm packages installed. Try it out:

var whyIsNodeRunning = require("why-is-node-running")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

why-is-node-running v1.2.3

Node is running but you don't know why? why-is-node-running is here to help you.

why-is-node-running

Node is running but you don't know why? why-is-node-running is here to help you.

$ npm install why-is-node-running

Usage

var log = require('why-is-node-running') // should be your first require
var net = require('net')

function createServer () {
  var server = net.createServer()
  setInterval(function () {}, 1000)
  server.listen(0)
}

createServer()
createServer()

setTimeout(function () {
  log() // logs out active handles that are keeping node running
}, 100)

Run the above script like this: node --expose-internals example.js. It will print the following:

There are 4 known handle(s) keeping the process running and 0 unknown
Known handles:

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:6  - setInterval(function () {}, 1000)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {

CLI

You can also run why-is-node-running standalone if you don't want to include it inside your code. Sending SIGUSR1 signal to the process will produce the log.

$ npm install why-is-node-running -g
$ why-is-node-running /path/to/some/file.js
probing module /path/to/some/file.js
kill -SIGUSR1 31115 for logging

To trigger the log do:

$ kill -SIGUSR1 31115

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free