2
crisz
8y

I really can't understand NodeJS. Why sometimes I require the same module in several files and sometimes I've to pass it as a parameter in the module.exports function of the other file? Where the hell I learn all this shit?

Comments
  • 1
    Why do you need to pass it exactly?
  • 0
    It's the passport module, once I need it to initialize it, once to configure it, once to declare the strategy, and the tutorial sometimes pass the variable as parameter and sometimes require it again.
    The same with express
  • 1
    @crisz

    What you should do is say the module is express initiate express:

    const app = require ('express')();

    Then pass app around to configure it.

    applyMiddleware(app);

    Then in applyMidleware.js add you Middleware where you were importing the model before

    Hope it helps!
  • 1
    @crisz What I usually do is initialize express in index.js and export the Instance, then require it in the middleware files
  • 0
    @djtouchette thank you very much. But why, if for example I want to use Router, I've to require express again?
Add Comment