https://github.com/cheap-glitch/why-is-node-still-running
🏃 Find out exactly why Node is still running.
https://github.com/cheap-glitch/why-is-node-still-running
asynchronous-tasks node-debugger node-module open-handles process-monitoring typescript-port
Last synced: about 1 year ago
JSON representation
🏃 Find out exactly why Node is still running.
- Host: GitHub
- URL: https://github.com/cheap-glitch/why-is-node-still-running
- Owner: cheap-glitch
- License: isc
- Created: 2020-12-13T21:19:44.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-13T18:11:23.000Z (over 5 years ago)
- Last Synced: 2025-03-19T02:22:49.276Z (about 1 year ago)
- Topics: asynchronous-tasks, node-debugger, node-module, open-handles, process-monitoring, typescript-port
- Language: TypeScript
- Homepage: https://npm.im/why-is-node-still-running
- Size: 337 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🏃 why-is-node-still-running


[](https://coveralls.io/github/cheap-glitch/why-is-node-still-running?branch=main)
> This is a port of mafintosh' [why-is-node-running](https://github.com/mafintosh/why-is-node-running)
> module to TypeScript, with modernized syntax and no dependencies.
```javascript
const { whyIsNodeStillRunning } = require('why-is-node-still-running');
const { createServer } = require('net');
const server = createServer();
server.listen(0);
whyIsNodeStillRunning();
// There are 2 handle(s) keeping the process running
```
## Installation
```shell
npm i -D why-is-node-still-running
```
## Usage
**Always import this module first** so that the asynchronous hook can be setup.
The hook will log to the console by default, but you can provide it with a
custom logger that implements `error()`.
### Example of usage with Jest
Sometimes Jest complains that there are asynchronous operations still hanging
after the tests have been completed. When the `--detectOpenHandles` flag gives
no output, you can try using this module to help pinpoint the cause:
```javascript
import { whyIsNodeStillRunning } from 'why-is-node-still-running';
afterAll(async () => {
// Do your actual cleanup here
// [...]
// Print the handles still opened
await new Promise(resolve => setTimeout(() => {
whyIsNodeStillRunning();
resolve();
}, 4000));
});
```
Don't forget to run Jest with `--useStderr` to show console output.
Alternatively, you can use this module to print some information about the stack
regularly while the tests are running (e.g. see [this comment](https://github.com/facebook/jest/issues/9473#issuecomment-675738694)).
## License
```text
Copyright (c) 2020-present, cheap glitch
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
```