-
-
Save elyosemite/dc40c6343d4bf1a41fad53c90cc2c853 to your computer and use it in GitHub Desktop.
| var myModule = require('myModule'); | |
| var myModuleInstance = new myModule(); | |
| myModule.hello(); | |
| myModule.goodbye(); |
Hey there, it says that myModule.hello is not a function, look at:
myModule.hello();
^
TypeError: myModule.hello is not a function
at Object. (/home/yuri/app.js:4:10)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Oh man! π You're calling that thing in the wrong place
myModule is the class
myModuleInstance is the right instance where you can call your methods
Well, both func.js and app.js are at the same place.
read what I wrote, I said the solution for you, in any moment I talked about where the files are
I got it man.
It worked out.
Thank you very much!
π π π
It worked out, but doesn't how say in this article: https://medium.freecodecamp.org/javascript-modules-a-beginner-s-guide-783f7d7a5fcc [PART - CommonJS].
I was trying to understand the CommonJS module, where it has put the path without ./.
Because of that I put var myModule = require('func.js'); without ./
you should do this
var myModule = require('./func.js')