Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Created March 15, 2024 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rms1000watt/6a7f3df602dd5e2b35e7dba6b93e5012 to your computer and use it in GitHub Desktop.
Save rms1000watt/6a7f3df602dd5e2b35e7dba6b93e5012 to your computer and use it in GitHub Desktop.
nodejs list, cleanup, create event listeners on process sigint
// from chatgpt
// list all event listeners on process
const eventNames = process.eventNames();
eventNames.forEach((eventName) => {
const listeners = process.listeners(eventName);
console.log(`Event: ${eventName}`);
console.log(`Listeners:`);
listeners.forEach((listener, index) => {
console.log(` Listener ${index + 1}: ${listener.toString()}`);
// Note: listener.toString() might not always give meaningful information,
// especially for native code. It's more useful for debugging simple listeners.
});
});
// cleanup sigint
process.removeAllListeners('SIGINT');
// create new listener
process.on('SIGINT', () => {console.log('stuff'); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment