Last active
March 8, 2023 09:43
-
-
Save AriPerkkio/ffd517437c50e64ccdc875b5e3553089 to your computer and use it in GitHub Desktop.
Node inspector worker_threads + child_process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Run as `node process.mjs` and open Chrome DevTools or similar debugging tool | |
*/ | |
import { fork } from "node:child_process"; | |
import { fileURLToPath } from "node:url"; | |
import inspector from "node:inspector"; | |
const filename = fileURLToPath(import.meta.url); | |
if (!process.env.SOME_FLAG) { | |
fork(filename, { | |
env: { SOME_FLAG: "true" }, // Just to indicate when running this file inside child_process | |
execArgv: [/* Just to indicate that no --inspect-brk is passed to process */], | |
}); | |
} else { | |
inspector.open(); | |
inspector.waitForDebugger(); | |
// Stopping in child process | |
debugger; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Run as `node threads.mjs` and open Chrome DevTools or similar debugging tool | |
*/ | |
import { isMainThread, Worker } from "node:worker_threads"; | |
import { fileURLToPath } from "node:url"; | |
import inspector from "node:inspector"; | |
const filename = fileURLToPath(import.meta.url); | |
if (isMainThread) { | |
new Worker(filename, { | |
execArgv: [/* Just to indicate that no --inspect-brk is passed to worker */] }); | |
} else { | |
inspector.open(); | |
inspector.waitForDebugger(); | |
// Stopping in worker thread! | |
debugger; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment