수색…


통사론

  • const readline = require ( 'readline')
  • readline.close ()
  • readline.pause ()
  • readline.prompt ([preserveCursor])
  • readline.question (query, callback)
  • readline.resume ()
  • readline.setPrompt (prompt)
  • readline.write (data [, key])
  • readline.clearLine (stream, dir)
  • readline.clearScreenDown (stream)
  • readline.createInterface (options)
  • readline.cursorTo (stream, x, y)
  • readline.emitKeypressEvents (stream [, interface])
  • readline.moveCursor (stream, 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