• 회원가입
  • 로그인
  • 구글아이디로 로그인

[module] Node.js - readline 모듈 - 한 번에 한 줄씩 데이터 스트림 읽기

1,511  
목차
  1. readline 모듈 예제 - 1회에 1라인씩 데이터 스트림 읽기
  2. readline 모듈 정의
  3. readline 모듈 구문
  4. readline 모듈 속성/메서드

 

readline 모듈 예제 - 1회에 1라인씩 데이터 스트림 읽기

1. C:\User\사용자명\index.html 생성. ※ 읽을 파일 생성.

 

<html>

<head>

<meta charset="UTF-8">

</head>

<body>

<h1>홈짱닷컴</h1>

<p>Homzzang.com</p>

</body>

</html>

 


2. C:\User\사용자명\hz.js 생성.

 

var readline = require('readline');

var fs = require('fs');


var myInterface = readline.createInterface({

  input: fs.createReadStream('index.html')

});


var lineno = 0;

myInterface.on('line', function (line) {

  lineno++;

  console.log('Line number ' + lineno + ': ' + line);

});

 


3. CMD 모드 실행 후, 아래 명령어 실행.

 

C:\User\사용자명>node hz.js

 


[결과값]

 

Line number 1: <html>

Line number 2: <head>

Line number 3: <meta charset="UTF-8">

Line number 4: </head>

Line number 5: <body>

Line number 6: <h1>홈짱닷컴</h1>

Line number 7: <p>Homzzang.com</p>

Line number 8: </body>

Line number 9: </html>

 

 

readline 모듈 정의

 

한 번에 한 줄씩 데이터 스트림을 읽는 방법을 제공.

 

 

readline 모듈 구문

 

var readline = require('readline');

 

 

readline 모듈 속성/메서드

 

clearLine()

지정된 스트림의 현재 행을 지우기.

 

clearScreenDown()

현재 커서 아래 위치에서 지정된 스트림을 지우기.

 

createInterface()

인터페이스 객체를 생성.

 

cursorTo()

커서를 지정된 위치로 이동.


emitKeypressEvents()

지정된 스트림에 대한 키 누르기 이벤트를 발생시킴.

 

moveCursor()

현재 위치를 기준으로 커서를 새 위치로 이동.

 



분류 제목
module Node.js - assert 모듈 - 표현식의 참거짓 평가.
module Node.js - buffer 모듈 - 바이너리 데이터 처리. (= 버퍼 모듈)
module Node.js - child_process 모듈 - 자식 프로세스 실행.
module Node.js - cluster 모듈 - 단일 노드 프로세스를 여러 프로세스로 분할.
module Node.js - crypto 모듈 - OpenSSL 암호화 기능을 처리. (= 크립토모듈)
module Node.js - dgram 모듈 - UDP 데이터 그램 소켓의 구현을 제공.
module Node.js - dns 모듈 - DNS 조회 및 도메인 관련 작업 수행.
module Node.js - domain 모듈 - 처리 안 된 에러 처리. [폐기예고]
module Node.js - events 모듈 - 이벤트 처리.
module Node.js - fs 모듈 ★ - 파일 시스템. (= 파일읽기, 파일생성, 파일수정, 파일삭제, 파일명변경…
module Node.js - http 모듈 ★ - Node.js를 HTTP 서버로 사용. (= http 통해서 데이터 …
module Node.js - https 모듈 - Node.js를 HTTPS 서버로 사용. (= https 통해서 데이터…
module Node.js - net 모듈 - 서버와 클라이언트 생성.
module Node.js - os 모듈 - 운영체제에 대한 정보 제공.
module Node.js - path 모듈 ★ - 파일 경로 처리.
module Node.js - punycode 모듈 - 문자 인코딩 방식. [폐기예고]
module Node.js - querystring 모듈 - URL 쿼리 문자열을 구문 분석.
module Node.js - readline 모듈 - 한 번에 한 줄씩 데이터 스트림 읽기
module Node.js - stream 모듈 - 스트리밍 데이터 처리.
module Node.js - string_decoder 모듈 - Buffer 객체를 문자열로 디코딩.
1/2
목록
찾아주셔서 감사합니다. Since 2012