Created
December 20, 2017 20:53
-
-
Save geoffb/c71de15fcdc4aaf41ed954b098185cd7 to your computer and use it in GitHub Desktop.
Simple example of a command REPL 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
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