0

Why is the node js require function being shown on a browser (ie client side)?

Well i was going through some websites source code and i saw a require function ie) its a nodejs api for importing modules. It was listed under the webpack src section, and it had a folder named node_modules which had a bunch of "server side" js syntax !!

15th Oct 2021, 8:29 AM
_Zi_
_Zi_ - avatar
2 Respuestas
0
Because node js work on components For each component we have to make seperate file for that and after that we need to export it to main app. Js file And we know that it is a single page application or web So we have to import modules
15th Oct 2021, 8:37 AM
Musaif
0
The website you were looking at is using webpack to bundle its JavaScript code. Webpack is a tool that allows developers to write code in a modular way and then bundles all of the modules together into a single file that can be included on a web page. In this case, the require function you saw is being used by webpack to include the necessary modules in the bundled code. The require function is not a part of the browser JavaScript API, but is specific to node.js, which is a server-side JavaScript runtime environment. This means that the code you saw using the require function was likely intended to be run on the server, not in the browser. However, because webpack is bundling the code, it is ultimately being included in the page and executed on the client side. The node_modules folder you saw is a common location for storing third-party packages and modules that are installed via the node package manager (npm).
14th Dec 2022, 12:06 PM
Calviղ
Calviղ - avatar