Last active
March 9, 2019 17:36
-
-
Save AmanRaj1608/38b88186d72f6ef945cdd3f61c8742cc to your computer and use it in GitHub Desktop.
Taking Input in Node.js for competitive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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