I have a function that looks like:
module.exports = myFunction() {
//do some stuff
}
I can access it fine from other file using var myFunction = require(.thepath.js)
However how can i access it from the file that it was created.
I've tried myFunction()
and this.myFunction()
but neither work.
Thanks
You can save it to a variable then export the variable like so:
// Create the function
const myFunction = function() {
}
// Call the function
myFunction();
// Export the function
module.exports = myFunction
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