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