Hi this is my method in a node js file:
exports.start = function() { console.log(' in start of sender.js'); });
How can I call this method in the same js file? I tried calling start() and exports.start() but not successful.
To include functions defined in another file in Node. js, we need to import the module. we will use the require keyword at the top of the file. The result of require is then stored in a variable which is used to invoke the functions using the dot notation.
Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.
Use this code:
var start = exports.start = function() { console.log(' in start of sender.js'); });
or
function start() { console.log(' in start of sender.js'); }); exports.start = start; //you can call start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With