Beginner LevelNode JS
How do you build interactive CLI prompts using the node:readline module?
❓ Interview Prompt: Explain `node:readline` module, `createInterface({ input, output })`, prompt questions, and closing interfaces.
The 'node:readline' module reads line-by-line input from readable streams (like 'process.stdin'):
Promises API ('node:readline/promises'):
Provides 'async/await' prompt capabilities for building CLI tools!
Code Implementation Example
javascript
import readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
async function askUser() {
const rl = readline.createInterface({ input, output });
const name = await rl.question('What is your name? ');
console.log('Hello, ${name}!');
rl.close();
}
askUser();💡Building interactive CLI prompts using node:readline/promises.
🎯 Interview Key Takeaway
Use node:readline/promises for building interactive command-line interfaces with async/await.
#readline#CLI#Interactive Prompts#Beginner
Back to all Node JS Questions→