why-is-node-running

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

  • Owner: mafintosh/why-is-node-running
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

why-is-node-running

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

Installation

Node 8 and above:

npm i why-is-node-running -g

Earlier Node versions (no longer supported):

npm i why-is-node-running@v1.x -g

Usage

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

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

createServer()
createServer()

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

Save the file as example.js, then execute:

node ./example.js

Here's the output:

There are 5 handle(s) keeping the process running

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

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

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

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

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

CLI

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

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:

kill -SIGUSR1 31115

License

MIT

Main metrics

Overview
Name With Ownermafintosh/why-is-node-running
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2016-02-09 15:29:28
Pushed At2025-01-08 15:01:13
Last Commit At2025-01-08 16:00:59
Release Count24
Last Release Namev3.2.2 (Posted on 2025-01-08 16:01:02)
First Release Namev1.0.0 (Posted on 2016-02-09 16:29:25)
用户参与
Stargazers Count1.9k
Watchers Count18
Fork Count46
Commits Count72
Has Issues Enabled
Issues Count42
Issue Open Count9
Pull Requests Count35
Pull Requests Open Count0
Pull Requests Close Count10
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private