Saturday 13 May 2017

How do I exit node from my script?

In my script, I want to be able to quit node without doing it manually (CTRL-C), however process.exit() does not seem to work?

I tried a few different things but is this because I still have an active stream open? How would i go about closing all active streams?

var fs = require('fs'),
readline = require('readline');


var count = 0;

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});


process.stdin.on('data', function(data){ 

  console.log(data);
  process.stdin.destroy();

})

rl.on('line', function(line){
  count++;
  rl.close();
})


function getBytes(data){
   return Buffer.byteLength(data, 'utf8');
}




process.stdin.on('close', function(){
  console.log(getBytes(count));
  process.exit();
})



via sagnew

No comments:

Post a Comment