Suche…


Syntax

  • const readline = required ('readline')
  • readline.close ()
  • readline.pause ()
  • readline.prompt ([preserveCursor])
  • readline.question (Abfrage, Rückruf)
  • readline.resume ()
  • readline.setPrompt (Eingabeaufforderung)
  • readline.write (Daten [, Schlüssel])
  • readline.clearLine (Stream, Verzeichnis)
  • readline.clearScreenDown (Stream)
  • readline.createInterface (Optionen)
  • readline.cursorTo (Stream, x, y)
  • readline.emitKeypressEvents (Stream [, Schnittstelle])
  • readline.moveCursor (Stream, Dx, Dy)

Zeilenweises Lesen von Dateien

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');
});

Eingabeaufforderung für Benutzer über 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
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow