Skip to content

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

License

Notifications You must be signed in to change notification settings

meeh0w/why-is-node-running

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%