Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sigint

ChrisAckerman2MITdeprecated1.0.0

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Cleaner process interrupt handling.

control-c, ctrl-c, sig, signal, int, interrupt, term, terminate, exit, close, shutdown, sigint, sigterm

readme

sigint

Cleaner process interrupt signal handling.

Hooks standard input in raw mode to enable interupts in Windows as well as to hide the "^C" echoed to the terminal.

Installation

npm install sigint --save

Example

var sigint = require('sigint').create();

sigint.on('signal', function(source, count) {
    if (source === 'keyboard' && count === 1) {
        console.log('press Ctrl+C again to quit');
    } else {
        process.exit();
    }
});

You can bind to only keyboard or kill interrupts.

var sigint = require('sigint').create();

sigint.on('keyboard', function(count) {
    if (count === 1) {
        console.log('press Ctrl+C again to quit');
    } else {
        process.exit();
    }
});

sigint.on('kill', function(count) {
    process.exit();
});

You can also use the process "SIGINT" event directly.

var sigint = require('sigint').create();

process.on('sigint', function() {
    if (sigint.source() === 'keyboard' && sigint.count() === 1) {
        console.log('press Ctrl+C again to quit');
    } else {
        process.exit();
    }
});