why-is-node-running
Node is running but you don't know why? why-is-node-running is here to help you.
Last updated a year ago by jkoops .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install why-is-node-running 
SYNC missed versions from official npm registry.

why-is-node-running

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

Installation

If you want to use why-is-node-running in your code, you can install it as a local dependency of your project. If you want to use it as a CLI, you can install it globally, or use npx to run it without installing it.

As a local dependency

Node.js 20.11 and above (ECMAScript modules):

npm install --save-dev why-is-node-running

Node.js 8 or higher (CommonJS):

npm install --save-dev why-is-node-running@v2.x

As a global package

npm install --global why-is-node-running
why-is-node-running /path/to/some/file.js

Alternatively if you do not want to install the package globally, you can run it with npx:

npx why-is-node-running /path/to/some/file.js

Usage (as a dependency)

import whyIsNodeRunning from 'why-is-node-running' // should be your first import
import { createServer } from 'node:net'

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

startServer()
startServer()

// logs out active handles that are keeping node running
setImmediate(() => whyIsNodeRunning())

Save the file as example.js, then execute:

node ./example.js

Here's the output:

There are 4 handle(s) keeping the process running

# Timeout
example.js:6  - setInterval(() => {}, 1000)
example.js:10 - startServer()

# TCPSERVERWRAP
example.js:7  - server.listen(0)
example.js:10 - startServer()

# Timeout
example.js:6  - setInterval(() => {}, 1000)
example.js:11 - startServer()

# TCPSERVERWRAP
example.js:7  - server.listen(0)
example.js:11 - startServer()

Usage (as a CLI)

You can run why-is-node-running as a standalone if you don't want to include it inside your code. Sending SIGUSR1/SIGINFO signal to the process will produce the log. (Ctrl + T on macOS and BSD systems)

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

Usage (with Node.js' --import option)

You can also use Node's --import option to preload why-is-node-running:

node --import why-is-node-running/include /path/to/some/file.js

The steps are otherwise the same as the above CLI section

License

MIT

Current Tags

  • 3.2.2                                ...           latest (a year ago)

24 Versions

  • 3.2.2                                ...           a year ago
  • 3.2.1                                ...           a year ago
  • 3.2.0                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.2                                ...           4 years ago
  • 2.2.1                                ...           4 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.3                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.2.3                                ...           8 years ago
  • 1.2.2                                ...           10 years ago
  • 1.2.1                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 18
Last Month 4
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (3)

Copyright 2013 - present © cnpmjs.org | Home |