You will be fine

<Node.js> 1. Module

by BFine
반응형

1. Require


node1


exports.test= function() { // exports를 사용하면 외부 js파일에서 사용할 수 있다

console.log("Hello");

};

exports.test2="World!";



node2


var nd2=require("./node2"); // 확장자 없이

nd2.test();

console.log(nd2.test2);




실행

  

 



 







2.Inner Module



node.js 내장된 모듈 -> 위치 없이 이름만 





실행









3.External Module


var reqt=require("request");

console.log(reqt.initParams("http://www.naver.com"));


외부 모듈 -> https://www.npmjs.com/ 에서 확인 할 수 있다.


설치는 cmd 창-> 프로젝트 폴도로 위치 변경 -> npm install 모듈명


설치 후 에는 내부모듈처럼 사용하면 된다.


실행



    



               

 





반응형

'공부(2018~2019) - 스킨변경전 > Node.js' 카테고리의 다른 글

<Node.js> 3. Server  (0) 2018.04.03
<Node.js> 2. Event  (0) 2018.04.03
<Node.js> 0. Basic  (0) 2018.04.02

블로그의 정보

57개월 BackEnd

BFine

활동하기