Reputation: 36391
Let's say I need a promise module, and I am using it in multiple files, I include all those files in app.js
. Do I have to use require the promise module in each of them? Is there a way to pass it to the imported module?
Upvotes: 2
Views: 861
Reputation: 145994
Yes, you should put a var Promise = require('bluebird')
statement at the top of every file that uses it. This is how node/commonjs express dependencies. Sometimes people react to this initially by wanting to go back to global variables and just require something in one file and have it be implicitly/globally available in every other file in their application, but as an industry we have had years and years on both approaches and explicit dependency stating via require
makes dependency management more, well manageable, overall. This is especially true in the case of automated tooling (browserify, webpack, etc).
Upvotes: 3