Поиск…


Синтаксис

  • const readline = require ('readline')
  • readline.close ()
  • readline.pause ()
  • readline.prompt ([preserveCursor])
  • readline.question (запрос, обратный вызов)
  • readline.resume ()
  • readline.setPrompt (приглашение)
  • readline.write (данные [, ключ])
  • readline.clearLine (поток, каталог)
  • readline.clearScreenDown (поток)
  • readline.createInterface (варианты)
  • readline.cursorTo (поток, x, y)
  • readline.emitKeypressEvents (поток [, интерфейс])
  • readline.moveCursor (поток, dx, dy)

Пошаговое чтение файлов

const fs = require('fs');
const readline = require('readline');

const rl = readline.createInterface({
    input: fs.createReadStream('text.txt')
});

// Each new line emits an event - every time the stream receives \r, \n, or \r\n
rl.on('line', (line) => {
    console.log(line);
});

rl.on('close', () => {
    console.log('Done reading file');
});

Вызов пользовательского ввода через CLI

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question('What is your name?', (name) => {
    console.log(`Hello ${name}!`);

    rl.close();
});


Modified text is an extract of the original Stack Overflow Documentation
Лицензировано согласно CC BY-SA 3.0
Не связан с Stack Overflow