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

/console-read-write/

    Package Sidebar

    Install

    npm i console-read-write

    Weekly Downloads

    420

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    4.59 kB

    Total Files

    4

    Last publish

    Collaborators

    • keyvan-m-sadeghi
    • assister.ai