I decided to use RequireJS as my module loader in NodeJS.
Unfortunately, the modules I define don't have access to some of the "global" objects that would be be available if the modules were loaded using the CommonJS method. This includes the objects that are located in the module scope, such as __dirname
and __filename
.
Is there a relatively simple approach to using these objects in the RequireJS modules?
This is covered on the requirejs issues site on github (https://github.com/jrburke/requirejs/issues/89) and the workaround they seem to suggest is to use module.uri instead.
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