336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
모듈이란? 부품 이라고 이해하면 된다다.
const http = require('http'); // http라는 모듈(부품)이 필요하다. require라는 부품을 가져온다고 이해하면 쉽다.
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => { //http라는 모듈에는 createServer라는 함수를 가지고 있다.
res.statusCode = 200; //얘는 httpServer라는 객체를 호출함.
res.setHeader('Content-Type', 'text/plain'); // httpServer는 listion라는 메소드를 가지고 있기 때문에 호출할 수 있다.
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
[코드 출저]node js
nodejs는 기본적으로 여러가지 부품(모듈)을 제공한다.
nodejs홈페이지에 가서 Docs를 들어가면 이러한 부품(모듈)들을 이용 할 수 있다.
예를 들어,
module.js 라는 파일이 다음과 같다고 하면
var OS = require('os');
console.log(OS.platform());
-------------------------------------
cmd에서 node module.js를 치면
WIN64라는 결과를 얻을 수 있다.
'IT 인터넷 > node.js' 카테고리의 다른 글
[node js] 서버 만들기 코드 분석 (0) | 2017.11.08 |
---|---|
[node js] 동기와 비동기 프로그래밍 (0) | 2017.11.08 |
[node js] 콜백 함수 (0) | 2017.11.08 |
[node js] 다른 사람이 만든 npm 사용해보기 (0) | 2017.11.07 |
[node js] npm (0) | 2017.11.07 |