title: How to validate an numeric input in Node js?
body: <p>I'm trying a build a simple calculator in node.js which also should validate the inputs. Below is the following code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>process.stdout.write('A simple calculator created using node.js \n');
  
  var inputs = ['Please enter your first number','Please enter the second number','Please enter the operator'];
  var output1 = [];
  
  function ask(i) {
   process.stdout.write(`${inputs[i]}`);
   process.stdout.write(" : ");
  }
  ask(0);
  process.stdin.on('data',(data)=&gt; {
   if(typeof data != "number"){
    console.log(ask(0));
   } else {
   output1.push(data); 
   console.log('The given input is ' + output1);
  }
  }
  );</code></pre>
  </div>
  </div>
  </p>
  
  <p>I would want the console to loop back to the function ask() if my input is not a number. Below should be the ideal output </p>
  
  <p>Output :
  Please enter your first number : p
  Please enter your first number : 1
  The given input is 1</p>
  
  <p>I know there are some flaws in my code, but not sure how to correct it. Pls help.</p>