Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/why-is-node-running
Node is running but you don't know why? why-is-node-running is here to help you.
https://github.com/mafintosh/why-is-node-running
Last synced: 4 days ago
JSON representation
Node is running but you don't know why? why-is-node-running is here to help you.
- Host: GitHub
- URL: https://github.com/mafintosh/why-is-node-running
- Owner: mafintosh
- License: mit
- Created: 2016-02-09T15:29:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T17:20:15.000Z (about 1 month ago)
- Last Synced: 2024-11-27T21:06:25.962Z (15 days ago)
- Language: JavaScript
- Size: 46.9 KB
- Stars: 1,872
- Watchers: 19
- Forks: 45
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome - mafintosh/why-is-node-running - Node is running but you don't know why? why-is-node-running is here to help you. (JavaScript)
- awesome-nodejs-cn - why-is-node-running - 当你不知道为何 Node.js 没有正确退出时... (包 / 调试 / 分析)
- awesome-nodejs - why-is-node-running - Node.js is running but you don't know why? ![](https://img.shields.io/github/stars/mafintosh/why-is-node-running.svg?style=social&label=Star) (Repository / Debugging)
- awesome-nodejs-cn - why-is-node-running - **star:1866** js正在运行,但你不知道为什么? (包 / 调试)
- awesome-nodejs - why-is-node-running - Node.js is running but you don't know why? (Packages / Debugging / Profiling)
- awesome-nodejs - why-is-node-running - Node is running but you don't know why? why-is-node-running is here to help you. - ★ 818 (Debugging / Profiling)
- awesome-node - why-is-node-running - Node.js is running but you don't know why? (Packages / Debugging / Profiling)
- awesome-f2e-libs - **why-is-node-running** - 检查 node 没退出的原因。 (命令行 / redux 扩展)
- awesome-nodejs-cn - why-is-node-running - 当不明Node原因继续运行时,使用的分析工具 (目录 / 调试/分析)
- awesome-fe - **why-is-node-running** - 检查 node 没退出的原因。 (命令行 / macros)
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 [email protected]
```### 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