Région de recherche :

Date :

https://stackoverflow.com › questions › 9015836

Why doesn't JavaScript need a main() function? - Stack Overflow

Many programming languages require a special user-written function that marks the begin of the execution. For example, in C this function must always have the name main(). In JavaScript, however, such a function is not required.

https://stackoverflow.com › questions › 9475792

How does require () in node.js work? - Stack Overflow

The require is a function that takes one argument called path, in this case the path is ./mod.js. when the require is invoked, a sequences of tasks are happened: call Module.prototype.require function declared in lib/module.js which assert that the path exists and was a string.

How does require () in node.js work? - Stack Overflow

https://www.freecodecamp.org › news › requiring-modules-in-node-js-everything-you-need-to...

Requiring modules in Node.js: Everything you need to know

There is also require.main which can be helpful to determine if the script is being required or run directly. Say, for example, that we have this simple printInFrame function in print-in-frame.js:

Requiring modules in Node.js: Everything you need to know

https://nodejs.org › api › modules.html

Modules: CommonJS modules | Node.js v22.9.0 Documentation

When a file is run directly from Node.js, require.main is set to its module. That means that it is possible to determine whether a file has been run directly by testing require.main === module.

https://developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Modules

JavaScript modules - MDN Web Docs

Node.js has had this ability for a long time, and there are a number of JavaScript libraries and frameworks that enable module usage (for example, other CommonJS and AMD -based module systems like RequireJS, Webpack, and Babel). All modern browsers support module features natively without needing transpilation.

https://www.freecodecamp.org › news › how-to-use-the-javascript-require-function

How to Use the require() Function in JS - freeCodeCamp.org

To include a module with the require () function, that module must be saved with a .js extension instead of .mjs when the import () statement is used. In this article, you have learned what the require () function does, how it works, and when you can use it in Node.js.

How to Use the require() Function in JS - freeCodeCamp.org

https://www.sitepoint.com › understanding-requirejs-for-effective-javascript-module-loading

Understanding RequireJS for Effective JavaScript Module Loading - SitePoint

RequireJS is a well known JavaScript module and file loader which is supported in the latest versions of popular browsers. In RequireJS we separate code into modules which each handle a single...

Understanding RequireJS for Effective JavaScript Module Loading - SitePoint

https://sebhastian.com › javascript-require-is-not-defined

JavaScript fix ReferenceError: require is not defined - sebhastian

This error occurs because JavaScript doesn’t understand how to handle the call to the require function. To fix this error, you need to make sure that the require function is available under your JavaScript environment.

JavaScript fix ReferenceError: require is not defined - sebhastian

http://fredkschott.com › post › 2014 › 06 › require-and-the-module-system

The Node.js Way - How `require()` Actually Works - Fred K. Schott

Almost any Node.js developer can tell you what the require() function does, but how many of us actually know how it works? We use it every day to load libraries and modules, but its behavior otherwise is a mystery. Curious, I dug into Node core to find out what was happening under the hood.