Posts

Showing posts with the label Nodejs

Node.js의 유용한 모듈 소개

Node.js에서는 475,000개에 달하는 정말 많은 모듈이 존재합니다. 그중에서 제가 사용해 봤던 몇몇 유용한 모듈을 소개할까 합니다. 1. url (표준모듈) url 모듈은 상대URL 을 절대URL 로 변경 해주는 등 url 사용에 대한 다양한 기능을 제공하고 있습니다. 간단한 기능 API 는 아래와 같습니다. url.resolve(from, to) // 상대경로를 절대경로로 변경하여 줍니다. url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) // url 문자열(urlStr)을 url 객체로 변환하여 리턴합니다. url.format(urlObj) // urlObj객체를 URL문자열로 변환하여 리턴합니다. 1.1. 설치 표준모듈이라 Node.js에 포함되어 있으므로 별도의 설치는 필요없습니다. 1.2. 간단한 사용예제 var url = require('url'); // 상대 URL을 절대 URL로 변경 url.resolve('/one/two/three', 'four') // '/one/two/four' url.resolve('http://example.com/one', '/two') // 'http://example.com/two' url.resolve('http://example.com/depth1/depth2/one', '/one') // 'http://example.com/one' url.resolve('http://example.com/depth1/depth2/one', '../two') // 'http://example.com/depth1/two' url.resolve(&#