Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 306
thinkbot Avatar asked Dec 18 '18 04:12

thinkbot


People also ask

Where is Node.js source code?

The source code can be found at https://github.com/nodejs/node. This assumes that you are a JavaScript developer approaching the project. If you are a C++ programmer, for example, your path will likely be different.

What purpose does the require () method serve in JavaScript?

The require() method is used to load and cache JavaScript modules. So, if you want to load a local, relative JavaScript module into a Node. js application, you can simply use the require() method.

What is Node.js source code?

js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on a JavaScript Engine (i.e. V8 engine) and executes JavaScript code outside a web browser, which was designed to build scalable network applications.

Can I use require in js file?

“Require” is built-in with NodeJS With require , you can include them in your JavaScript files and use their functions and variables. However, if you are using require to get local modules, first you need to export them using module. exports . For example, let's assume that you have a file called blogDetails.


1 Answers

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

like image 91
thinkbot Avatar answered Oct 16 '22 07:10

thinkbot