我有module.export.process
我想执行此功能当我命令节点app.js
它应该执行该功能,我试图再次导出它但是这不起作用,我是nodejs的新手任何帮助将不胜感激。
app.js
// Include blinlib to access blink common utility modules
var blinklib = require('../blinklib.js');
var snmp = require("net-snmp");
var logger = blinklib.logger('actors.snmp');
var msg = require('./event.js');
var config = require('./config.json');
console.log('CONFIG', config);
var session = snmp.createSession("127.0.0.1", "public");
module.exports.process = function (msg, config, callback) {
var informOid = msg.event.body.data[0].oid;
var varbinds = msg.event.body.data;
var options = {upTime: 1000};
logger.info("Processing message: ", msg.event.message);
varbinds.forEach(function (value) {
value.type = snmp.ObjectType.OctetString;
});
try {
session.inform(informOid, varbinds, options, function (error) {
if (error)
console.error(error);
});
} catch (e) {
logger.info(e);
}
}
module.export = process;
答案 0 :(得分:3)
只需将流程功能导出到外部模块:
process.js
//Import dependencies
function process(msg, config, callback){}
module.exports = process;
app.js
var process = require('./process.js');
//declare msg, config, callback
process(msg, config, callback);
或者,不要导出任何内容并以IIFE身份执行流程:
(function process(msg, config, callback){})();