# why-is-node-running

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

Latest version **3.2.2** (published 2025-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install why-is-node-running
pnpm add why-is-node-running
yarn add why-is-node-running
bun add why-is-node-running
```

Provides the command `why-is-node-running`.

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.2 |
| Published | 2025-01-08 |
| First published | 2016-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20.11 |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1946 |
| Author | Mathias Buus |
| Maintainers | mafintosh, yoshuawuyts, jkoops |
| Keywords | debug, devops, test, events, handles |

## Links

- npm: https://www.npmjs.com/package/why-is-node-running
- Repository: https://github.com/mafintosh/why-is-node-running
- Issues: https://github.com/mafintosh/why-is-node-running/issues
- npm.io page: https://npm.io/package/why-is-node-running

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 3.2.2 (latest) — 2025-01-08
- 3.2.1 — 2024-10-29
- 3.2.0 — 2024-07-12
- 3.1.0 — 2024-07-09
- 3.0.0 — 2024-07-08
- 2.3.0 — 2024-07-08
- 2.2.2 — 2022-04-26
- 2.2.1 — 2022-01-27
- 2.2.0 — 2020-06-16
- 2.1.2 — 2020-03-07
- 2.1.1 — 2020-03-06
- 2.1.0 — 2019-04-03
- 2.0.3 — 2018-08-30
- 2.0.2 — 2018-03-05
- 2.0.1 — 2018-03-01
- … 9 more at https://npm.io/package/why-is-node-running/versions

## README

# 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):

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

Node.js 8 or higher (CommonJS):

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

### As a global package

```bash
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`](https://docs.npmjs.com/cli/commands/npx):

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

## Usage (as a dependency)

```js
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:

```bash
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)

```bash
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`](https://nodejs.org/api/cli.html#--importmodule) option to preload `why-is-node-running`:

```bash
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

---
_Source: https://npm.io/package/why-is-node-running · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
