8

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, here's the relevant content from that post: <blockquote> jrburke commented April 09, 2011 </blockquote> b> If you do the following, you should be able to get the path and dir> for the current module: {{{ define(['module', 'path'], function (module, path) { console.log("module's path is: " + module.uri); console.log("module's dir is: " + path.dirname(module.uri)); }); }}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.