Skip to content

Instantly share code, notes, and snippets.

@Tonyce
Created April 21, 2020 08:24
Show Gist options
  • Save Tonyce/bdb7a3473063dbfdd5a9c3027f8e0e86 to your computer and use it in GitHub Desktop.
Save Tonyce/bdb7a3473063dbfdd5a9c3027f8e0e86 to your computer and use it in GitHub Desktop.
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('OHAI> ');
rl.prompt();
rl.on('line', function(line) {
switch(line.trim()) {
case 'exit':
rl.close();
break;
case 'hello':
console.log('world!');
break;
default:
console.log('Say what? I might have heard `' + line.trim() + '`');
break;
}
rl.prompt();
}).on('close', function() {
console.log('Have a great day!');
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment