console-read-write

Utilities for reading from and writing to the Node.js console

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
console-read-write
0.1.15 years ago5 years agoMinified + gzip package size for console-read-write in KB

Readme

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