javascriptvorpal.js

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?


Solution

  • 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')();
    
    vorpal
      .delimiter('myapp$')
      .show();