Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

cheap-glitch/why-is-node-still-running

Repository files navigation

πŸƒ why-is-node-still-running

License Latest release Coverage status

This is a port of mafintosh' why-is-node-running module to TypeScript, with modernized syntax and no dependencies.

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

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:

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).

License

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.

Contributors 2

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /