Repository: nodejs/node
Pull request: doc,module: add missing doc for syncHooks.deregister()

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: doc/api/module.md
patch: @@ -235,9 +235,14 @@ changes:
 * `options` {Object}
   * `load` {Function|undefined} See [load hook][]. **Default:** `undefined`.
   * `resolve` {Function|undefined} See [resolve hook][]. **Default:** `undefined`.
+* Returns: {Object} An object with the following property:
+  * `deregister()` {Function} Remove the registered hooks so that they are no
+    longer called. Hooks are otherwise retained for the lifetime of the running
+    process.
 
 Register [hooks][] that customize Node.js module resolution and loading behavior.
-See [Customization hooks][].
+See [Customization hooks][]. The returned object can be used to
+[deregister the hooks][deregistration of synchronous customization hooks].
 
 ### `module.stripTypeScriptTypes(code[, options])`
 
@@ -764,6 +769,63 @@ hook to signal that the chain is intentionally ending at your hook.
 If a hook should be applied when loading other hook modules, the other hook
 modules should be loaded after the hook is registered.
 
+#### Deregistration of synchronous customization hooks
+
+The object returned by `registerHooks()` has a `deregister()` method that can be
+used to remove the hooks from the chain. Once `deregister()` is called, the hooks
+will no longer be invoked during module resolution or loading.
+
+This is currently only available for synchronous hooks registered via `registerHooks()`, not for asynchronous
+hooks registered via `module.register()`.
+
+```mjs
+import { registerHooks } from 'node:module';
+
+const hooks = registerHooks({
+  resolve(specifier, context, nextResolve) {
+    console.log('resolve hook called for', specifier);
+    return nextResolve(specifier, context);
+  },
+  load(url, context, nextLoad) {
+    return nextLoad(url, context);
+  },
+});
+
+// At this point, the hooks are active and will be called for
+// any subsequent import() or require() calls.
+await import('./my-module.mjs');
+
+// Later, remove the hooks from the chain.
+hooks.deregister();
+
+// Subsequent loads will no longer trigger the hooks.
+await import('./another-module.mjs');
+```
+
+```cjs
+const { registerHooks } = require('node:module');
+
+const hooks = registerHooks({
+  resolve(specifier, context, nextResolve) {
+    console.log('resolve hook called for', specifier);
+    return nextResolve(specifier, context);
+  },
+  load(url, context, nextLoad) {
+    return nextLoad(url, context);
+  },
+});
+
+// At this point, the hooks are active and will be called for
+// any subsequent require() calls.
+require('./my-module.cjs');
+
+// Later, remove the hooks from the chain.
+hooks.deregister();
+
+// Subsequent loads will no longer trigger the hooks.
+require('./another-module.cjs');
+```
+
 #### Hook functions accepted by `module.registerHooks()`
 
 <!-- YAML
@@ -1995,6 +2057,7 @@ returned object contains the following keys:
 [asynchronous `resolve` hook]: #asynchronous-resolvespecifier-context-nextresolve
 [asynchronous hook functions]: #asynchronous-hooks-accepted-by-moduleregister
 [caveats of asynchronous customization hooks]: #caveats-of-asynchronous-customization-hooks
+[deregistration of synchronous customization hooks]: #deregistration-of-synchronous-customization-hooks
 [hooks]: #customization-hooks
 [load hook]: #synchronous-loadurl-context-nextload
 [module compile cache]: #module-compile-cache