Bun Listen for CTRL+C

Listen for CTRL+C

jarle Updated

File contents

Listen for CTRL+C

The ctrl+c shortcut sends an interrupt signal to the running process. This signal can be intercepted by listening for the SIGINT event. If you want to close the process, you must explicitly call process.exit().

process.on("SIGINT", () => {
  console.log("Ctrl-C was pressed");
  process.exit();
});

See Docs > API > Utils for more useful utilities.

jarle/bun-skills/tree/main/skills/bun-guides-process-ctrl-c commit 2d6ca9abbe

Frequently asked questions

npx skillmds@latest add jarle/bun-listen-for-ctrl-c