To export just a single function from a module:
Module file:
//function definition
function function_name(){...}
//Export
module.exports = function_name;
Import:
const function_name = require('<relative path>/module_name');
//call imported function
function_name();
To export multiple functions:
Module file:
//function definitions
function function_name1(){...}
function function_name2(){...}
//Exports
module.exports.function_name1= function_name1;
module.exports.function_name2= function_name2;
Import:
const module_name = require('<relative path>/module_name');// This returns module object with the functions from module's file.
//call imported function
module_name.function_name1();
module_name.function_name2();
(). You don[t want to invoke it, you just want to reference it. Also, you haven't definedmqtt_messsageReceivedanywhere in the code above...module.exports = messageReceived;would be goodvar mqtt_messageReceived = require('./somefile');and callmqtt_messageReceived