thinkbot
thinkbot

Reputation: 523

Node.js source code of require() function

According to the document (https://nodejs.org/api/globals.html), require() function is one of the global objects/functions. But I'm having a hard time finding its source code on Github. Are they written in JS or C++? I was looking for them in https://github.com/nodejs/node project.

Upvotes: 7

Views: 3301

Answers (2)

thinkbot
thinkbot

Reputation: 523

To answer my own question, I think it's defined in loader.js. And you can see it's implemented for all modules. It seems to be mapped to global.require in node.js

Upvotes: 3

ic3b3rg
ic3b3rg

Reputation: 14927

This seems to be it (in node/lib/internal/modules/cjs/helpers.js).

Upvotes: 3

Related Questions