Josh Josh - 1 year ago 123
Javascript Question

How do I run code on exiting a Vorpal.js app?

I'm writing a vorpal.js app that loads a file on launch, and should write a modified version of the file on exit. How do I run code on exit? Is there some place I can attach a callback or something?

Answer Source

You can add a hook to the node.js process exit event.

process.on('exit', (code) => {
    // Do some cleanup here
    console.log(`About to exit with code: ${code}`);

const vorpal = require('vorpal')();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download