Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NodeJS global module objects in RequireJS modules

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?

like image 843
schutterp Avatar asked Jan 27 '12 00:01

schutterp


1 Answers

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.

like image 198
Timothy Strimple Avatar answered Sep 28 '22 11:09

Timothy Strimple