노드JS | require() 다른 페이지 코드 추가

|

요약

엄격 모드 를 사용중인 때에는 해당 코드를 사용할 수 없습니다.

use strict;

다른 파일의 Node.js 파일을 불러오는 방법입니다.

사용법

// tools.js
module.exports = {
  foo: function () {
    // whatever
  },
  bar: function () {
    // whatever
  }
};

var zemba = function () {
}

// app.js
var tools = require('./tools');
console.log(typeof tools.foo); // => 'function'
console.log(typeof tools.bar); // => 'function'
console.log(typeof tools.zemba); // => undefined

참조

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

클릭하여 복사