2

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;

1 Answer 1

3

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){})(); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.