NodeJS Prompt

Posted by Joe Enos on August 17, 2021 · 1 min read

Sometimes you just need a simple terminal application that requests user input. Here’s a quick way to prompt the user for input:

const readline = require("readline");
const rl = readline.createInterface(process.stdin, process.stdout);

rl.on("line", line => {
console.log(`You typed ${line}`);
rl.prompt();
});

rl.setPrompt("Action> ");
rl.prompt();