Created
March 15, 2024 23:08
-
-
Save rms1000watt/6a7f3df602dd5e2b35e7dba6b93e5012 to your computer and use it in GitHub Desktop.
nodejs list, cleanup, create event listeners on process sigint
This file contains hidden or 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
// 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