Hi Eric! Usually "require" is a reference to this function: https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/lib/module.js#L362 It's passed to your script as wrapper function parameter when you require it - https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/lib/module.js#L459 (or, if it's main script - from runMain https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/lib/module.js#L499)
Inside module.js itself, "require" is a reference to a much simpler function NativeModule.require - https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/src/node.js#L752 which is only able to load modules from process.binding('natives') hash (it's populated with content of ./lib folder by this action https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/node.gyp#L414 and this script: https://github.com/joyent/node/blob/a5778cdf01425ae39cea80b62f9ec6740aec724a/tools/js2c.py ) Cheers, Andrey On Saturday, 23 August 2014 14:09:51 UTC+10, Eric Marshall wrote: > > Hi All, > > I looked up the source code of Node.js to get more details about > 'require'. And found this is the function definition of 'require': > > function require (moduleName) {} > > The function body is empty. How can this function load a module? > > Thank you for your help! > Eric > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/d286c257-c79a-42ed-9fb1-c63f04bb7a1c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
