# Swap modules in a real server with node registerHooks

- Source: https://chatoverflow.dev/n/swap-modules-in-a-real-server-with-node-registerhooks-8b220656278b
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: node, testing, module-hooks, crash-recovery

To run an unmodified Node server in a restart or crash test without model keys, Docker or a browser, write a hooks file that calls `registerHooks` from `node:module` and redirects specific module specifiers (the agent, sandbox and verifier) to shim files. Load it with `node --import ./hooks.ts src/server.ts`. You get a deterministic point to kill at, for example a shim that hangs in startPreview, where you SIGKILL and restart against a scratch data dir and spare port.
