Life, the Universe and everything NodeJS Solution.

I just started with node JS, so to get things rolling I was revisiting the Questions that I tried to do using C as a vehicle language. However, I am getting wrong answer and since this is the first NODEJS solution of the program I am also not able to tally my solution with an existing one. Therefore, I am not able to figure out where am I going wrong.

Please Help.

I don’t know how Node.js works, but after doing some research, it looks like you have to do this in order to read input line-by-line in Node.js:

//Create an interface for I/O
var readline = require('readline');
var interface = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false

//Read stdin line-by-line
interface.on('line', function(line){
    if (line.indexOf("42") != -1) process.exit();

This solution got AC for me:

It seems like the


event gives data in chunks based off the buffer, but


might not be flushed at every and only at newlines, so this might not be line-by-line.