async-hook-jl is a Node.js library that provides a high-level, stable abstraction over Node.js's internal, currently undocumented `AsyncWrap` API. It enables developers to inspect and hook into the lifecycle of "handle objects" (internal resources like network connections, timers, etc.) within the Node.js runtime. This includes events like initialization (`init`), pre-execution (`pre`), post-execution (`post`), and destruction (`destroy`) of asynchronous operations. The library aims to address some inconsistencies in the native `AsyncWrap` API, offer a more uniform interface, and crucially, allow multiple hooks to be registered simultaneously. The current stable version is 1.7.6, with recent updates focusing on compatibility and minor fixes rather than new features. Its primary differentiator is making a powerful, low-level internal Node.js API accessible and more robust for userland modules, with the long-term hope that similar functionality will eventually be integrated directly into Node.js core.
npm install async-hook-jlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `async-hook-jl`, register all four types of lifecycle hooks (`init`, `pre`, `post`, `destroy`), enable them, and observe their output during a simple `setTimeout` operation.
Monitor Node.js release notes closely for changes to internal async APIs. Test `async-hook-jl` extensively when upgrading Node.js versions. Consider forking or using a specific, tested version of Node.js for critical applications.
Only disable hooks if you are certain no other part of your application or its dependencies relies on `async-hook-jl` being active. Prefer conditional hook registration or removal over global disabling where possible.
Always use `asyncHook` (singular) when interacting with the module's exported object and its methods (e.g., `asyncHook.removeHooks(...)`).
Always use `const asyncHook = require('async-hook-jl');` to ensure correct module loading, especially in older Node.js versions or mixed CJS/ESM projects.Change `asyncHooks` to `asyncHook`. For example, `asyncHook.removeHooks(...)` instead of `asyncHooks.removeHooks(...)`.
Ensure `const asyncHook = require('async-hook-jl');` is used at the top of your file. Verify that `async-hook-jl` is correctly installed in `node_modules` and that no other variable named `asyncHook` is conflicting.Ensure you call `asyncHook.enable();` after calling `asyncHook.addHooks(...)` to activate the hook callbacks.
No dependency data recorded yet.