title: How to process standard input NodeJS, in the console?
body: <p>I want to write NodeJS code for solving problems like ICPC. The following is an example using a template of www.hackerrank.com for submitting in JavaScript:</p>
  
  <pre><code>process.stdin.resume();
  process.stdin.setEncoding('ascii');
  
  var input_stdin = "";
  var input_stdin_array = "";
  var input_currentline = 0;
  process.stdin.on('data', function (data) {
      input_stdin += data;
  });
  process.stdin.on('end', function () {
      input_stdin_array = input_stdin.split("\n");
      main();    
  });
  function readLine() {
      return input_stdin_array[input_currentline++];
  }
  /////////////// ignore above this line ////////////////////
  function main() {
      var s = readLine();
      s = s.split(",");
      s = s.join(" ");
      process.stdout.write(s);
  }
  </code></pre>
  
  <p>I want to code offline, so I need to run the programs in my Windows console. For runnig the srcript using <em>C:users\user>node path\file.js</em> I added at the end of the code the line</p>
  
  <pre><code>main();
  </code></pre>
  
  <p>and the scripts runs, but it doesn't process the standard input. It gives me and error in "s=s.split()", the error is the following <em>"TypeError: Cannot read property 'split' of undefined"</em>. If anyone know how to do <em>node</em> process the standard input please help me.</p>