Amit
Amit

Reputation: 11

How to disable debugging with a signal in nodejs?

We can start debugger in nodejs using kill -USR1 PID. How can we disable it using any signal or any other way without terminating the worker?

Reference - https://nodejs.org/en/docs/guides/debugging-getting-started/#enable-inspector

Upvotes: 1

Views: 1552

Answers (1)

LazyMonkey
LazyMonkey

Reputation: 527

While SIGUSR1 is used to start the debug inspector (equivalent to running node with the --inspect flag), you can customize SIGUSR2 to close the inspector without killing the process.

Adding something like this to your main app should add that behavior.

const inspector = require('inspector');

process.on('SIGUSR2', () => {
    console.log('Received SIGUSR2. Closing inspector.');
    inspector.close();
});

https://nodejs.org/api/inspector.html#inspector_inspector_close

Upvotes: 2

Related Questions