Friday 14 April 2017

Reusing process.on in nodejs

I have a snippet like this, that I use for CTRL+C interruption in several nodejs scripts belonging to the same project:

process.on('SIGINT', function () {
    console.log("Caught interrupt signal");

    if (i_should_exit)
        process.exit();
});

I am familiarised with module exports in node, so I can successfully reuse variables and functions.

However I am newbie enough to not know how to make a simple reuse of the before mentioned snippet in all my scripts.

Please, could someone orientate me with the best practises in this case?

Thanks a lot.



via prussian blue

No comments:

Post a Comment