Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

console-read-write

0.1.1 • Public • Published

npm version Build Status

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.

Licence

MIT

Install

npm i console-read-write

DownloadsWeekly Downloads

108

Version

0.1.1

License

MIT

Unpacked Size

4.59 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar