Reputation: 7123
I have module.export.process
i want to execute this function when i command node app.js
it should execute the function, i tried to export it again but that does not work, I am new to nodejs any help will be appreciated.
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;
Upvotes: 2
Views: 1111
Reputation: 18889
Just export the process function to an external module:
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);
Alternatively, don't export anything and execute process as IIFE:
(function process(msg, config, callback){})();
Upvotes: 3