기본 내장 모듈중에 주로 많이 쓰이는 모듈을 알아보자


url모듈

var url = require(‘url’);

parse(String)

URL문자열을 URL객체로 변환해 리턴

parse(String, true)

두 번째 매개변수에 true하면 query를 사용

format(Obj)

URL객체를 URL문자열로 변환해 리턴

resolve(from, to)

매개 변수를 조합하여 완전한 URL 문자열 생성

 

util 모듈

var util = requird(‘util’);

format

매개변수로 입력한 문자열을 조합해 리턴

 

File System 모듈

var fs = require(‘fs);

readFile(file, encoding, callback)

파일을 비동기로 읽음

readFileSync(file, encoding)

파일을 동기로 읽음

writeFile(file, data, encoding, callback)

파일을 비동기로 씀

writeFileSync(file, data, encoding)

파일을 동기로 씀

 

encoding 방식 : utf8

파일을 읽고 쓸때는 반드시 예외처리를 할 것

동기방식

try{}catch(e){} 사용

비동기 방식

if(err){}else{}사용


'Programming > Node.JS' 카테고리의 다른 글

http모듈  (0) 2016.09.03
Event개념 이해  (0) 2016.09.03
전역 객체에 대하여  (0) 2016.09.03
node.js 특징  (0) 2016.09.03
Node.js 에서 JSON 사용하기  (0) 2016.08.27

+ Recent posts