Skip to content

Instantly share code, notes, and snippets.

@AmanRaj1608
Last active March 9, 2019 17:36
Show Gist options
  • Save AmanRaj1608/38b88186d72f6ef945cdd3f61c8742cc to your computer and use it in GitHub Desktop.
Save AmanRaj1608/38b88186d72f6ef945cdd3f61c8742cc to your computer and use it in GitHub Desktop.
Taking Input in Node.js for competitive
// Get process.stdin as the standard input object.
var standard_input = process.stdin;
// Set input character encoding.
// Although not mendatory
standard_input.setEncoding('utf-8');
// Prompt user to input data in console.
console.log("Enter your name");
// Input starts
standard_input.on('data', function (data) {
if(data === 'exit\n'){
// Program exit.
console.log("User input complete, program exit.");
process.exit();
}
else{
// Print user input in console.
console.log('Hello ' + data + '!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment