console-read-write
v0.1.1
Published
Utilities for reading from and writing to the Node.js console
Downloads
1,174
Readme
console-read-write
Read from and write to the Node.js console. A simple async/await
interface for the readline
module
Install
npm i --save console-read-write
Usage
const io = require('console-read-write');
async function main() {
// Simple readline scenario
io.write('I will echo whatever you write!');
io.write(await io.read());
// Simple question scenario
io.write(`hello ${await io.ask('Who are you?')}!`);
// Since you are not blocking the IO, you can go wild with while loops!
let saidHi = false;
while (!saidHi) {
io.write('Say hi or I will repeat...');
saidHi = await io.read() === 'hi';
}
io.write('Thanks! Now you may leave.');
}
main();
// I will echo whatever you write!
// > ok
// ok
// Who are you? someone
// hello someone!
// Say hi or I will repeat...
// > no
// Say hi or I will repeat...
// > ok
// Say hi or I will repeat...
// > hi
// Thanks! Now you may leave.