MEAN STACK node.js
테스트 환경 : Windows 10 64-bit
전역에서 참조 가능한 Global Objects
설치는 필요없고 그냥 사용하면 된다.
__filename : 현재 실행되는 코드의 파일명
__dirname : 실생되는 js파일이 존재하는 디렉토리 경로
setTimeout(callback, milliseconds) : callback 함수를 한번만 수행
clearTimeout(t) : setTimeout으로 생성된 타이머를 멈춤.
setInterval(collback, milliseconds) callback 함수를 반복 수행
clearInterval(t) : setInterval으로 생성된 타이머를 멈춤.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | console.log("파일명 : " + __filename ); console.log("디렉토리명 : " + __dirname ); function printHello(){ console.log( "Hello, World!"); } // 2초후 함수(printHello)를 호출 var time = setTimeout(printHello, 2000); // time을 멈춘다. // clearTimeout(time); function printHello2(){ console.log("안녕, 월드!"); } // 2초마다 함수(printHello2)를 호출 var time2 = setInterval(printHello2, 2000); // time2를 멈춘다. //clearInterval(time2); | cs |
결과출력
파일명 : D:\Node_Web_App\global.js
디렉토리명 : D:\Node_Web_App
Hello, World!
안녕, 월드!
안녕, 월드!
안녕, 월드!
안녕, 월드!
^C
! setInterval 때문에 '안녕, 월드!'가 계속 출력 될 것이다. Ctrl + C로 출력을 멈출 수 있다.
clearTimeout과 clearInterval의 주석을 제거후 실행하면 바로 타이머가 멈추기 때문에 콘솔창에선 아무것도 확인할 수 없다.
참조 : http://www.tutorialspoint.com/nodejs/nodejs_global_objects.htm
'개발' 카테고리의 다른 글
[Node.js] Express Framework를 이용한 간단한 라우팅 (0) | 2015.12.24 |
---|---|
[Node.js] Web Module - server & client (0) | 2015.12.18 |
[Node.js] File System (0) | 2015.12.17 |
[Node.js] Streams 사용하기 (0) | 2015.12.16 |
[Node.js] buffer 사용하기 (0) | 2015.12.16 |