1
하나의 Javascript 파일에서 nodejs의 전역 변수 및 함수 세트를 내보내려고합니다. 테스트 노드 JS-include.js에nodejs에서 변수 및 함수 내보내기
가입일 노드 js.include.js
var GLOBAL_VARIABLE = 10;
exports.GLOBAL_VARIABLE = GLOBAL_VARIABLE;
module.exports = {
add: function(a, b) {
return a + b;
}
};
:
var includes = require('./node-js-include');
process.stdout.write("We have imported a global variable with value " + includes.GLOBAL_VARIABLE);
process.stdout.write("\n and added a constant value to it " + includes.add(includes.GLOBAL_VARIABLE, 10));
하지만 변수; 왜 안 GLOBAL_VARIABLE이
We have imported a global variable with value undefined
and added a constant value to it NaN
를 내보낼 : 나는 다음과 같은 출력을 얻을? 이 문제를 해결하는
가능한 중복 http://stackoverflow.com/questions/7137397/module -exports-vs-export-in-node-js) –