Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS - How to access a module.exports function in the same file

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

like image 481
userMod2 Avatar asked Aug 30 '17 05:08

userMod2


1 Answers

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
like image 148
Get Off My Lawn Avatar answered Oct 02 '22 21:10

Get Off My Lawn