Created
March 28, 2014 10:57
-
-
Save piotrek-k/9830119 to your computer and use it in GitHub Desktop.
Simple node code that wait for some commands. Found there: http://stackoverflow.com/questions/10428684/how-to-implement-console-commands-while-server-is-running-in-node-js
This file contains 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
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function (text) { | |
text.replace(/\r?\n|\r/g, ""); | |
console.log("Command: " + text + "textthatshouldbeinthesameline"); | |
if (text == 'quit') { | |
console.log("Quitting"); | |
done(); | |
} | |
}); | |
function done() { | |
console.log('Now that process.stdin is paused, there is nothing more to do.'); | |
process.exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment