Skip to content

Instantly share code, notes, and snippets.

@geoffb
Created December 20, 2017 20:53
Show Gist options
  • Save geoffb/c71de15fcdc4aaf41ed954b098185cd7 to your computer and use it in GitHub Desktop.
Save geoffb/c71de15fcdc4aaf41ed954b098185cd7 to your computer and use it in GitHub Desktop.
Simple example of a command REPL in Node.js
const readline = require("readline");
let input = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let queryCommand = () => {
input.question("Command: ", (command) => {
if (command === "exit") {
input.close();
} else {
commandHandler(command);
queryCommand();
}
});
};
let commandHandler = (command) => {
// TODO: Replace with custom command handling
console.info("User entered: " + command);
};
queryCommand();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment