2016-06-03 3 views
0

나는 nodejs에 익숙하다. event.js의 데이터를 같은 디렉토리에있는 app.js로 가져오고 싶지만 어떻게 작동시키는 지 아이디어를 얻지 못한다.nodejs를 사용하여 변수를 다른 파일로 내보내려면 어떻게해야합니까?

exports.message = message ; 

이 또한 방법을 이해하는 모듈을 노드로 살펴 :

는 app.js

var SnmpData = require('./event.js'); 
console.log('SNMP data',SnmpData); 

event.js

var message = { 
    event: { 
     header: { 
      eventSource: "d-sms" 
     }, 
     body: { 
      data: [ 
       { 
        oid: "1.3.6.1.4.140.625", 
        host: "135.89.157.201", 
        port: "162", 
        value: "Problem with monitoring device", 
        type: "" 
       }, 
       { 
        oid: "1.3.6.1.4.345.765", 
        host: "135.89.157.299", 
        port: "162", 
        value: "Problem with monitoring device-2", 
        type: "" 
       }], 
      message: "Activate Collaborate" 
     } 
    } 
} 
} 
+1

[Node.js module.exports의 용도는 무엇이며 어떻게 사용합니까?] (http://stackoverflow.com/questions/5311334/what-is-the-purpose-of-node) -js-module-exports-and-how-you-use-it) –

+0

덕분에 도움이되었습니다 – hussain

답변

1

events.js이의 말에 추가 모든 것이 작동합니다.

+0

고마워요! – hussain

+0

기꺼이 도와 드릴 수 있습니다 ^^! –

관련 문제