A module is a JavaScript file that can export elements from itself with the export keyword. Then, other modules can import them with an import statement. This allows us to separate code, but make it available where needed without polluting the global space. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules Answer from Giaddon on reddit.com
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Modules
JavaScript modules - JavaScript | MDN
The module specifier provides a string that the JavaScript environment can resolve to a path to the module file. In a browser, this could be a path relative to the site root, which for our basic-modules example would be /js-examples/module-examples/basic-modules.
🌐
W3Schools
w3schools.com › js › js_modules.asp
JavaScript Modules
A JavaScript module is usually a file, but it can also be an HTML script.
Discussions

The state of JavaScript modules

That was the best high-level overview of the struggles of the Node core team dealing with modules I've read yet. Unfortunately we're all stuck with transpiling and bundles for at least 5+ years because of browser support, but at least that gives them time to sort this out. Cheers to hoping that .mjs doesn't win the battle...

More on reddit.com
🌐 r/javascript
51
134
May 29, 2017
[shower thoughts] Why are JavaScript modules treated as objects instead of functions?
Because it's useful for a module to be able to export things besides functions. Besides, you can export a function, and a function is an object. More on reddit.com
🌐 r/node
91
62
December 5, 2021
Understanding JS modules
You're not showing your More on reddit.com
🌐 r/learnjavascript
4
8
August 17, 2022
Common JS vs ES Modules and why?
CommonJS is old, but Node tries to hold on to backwards compatibility as much as it can, but forward compatibility is a whole 'nother story. The major difference is, import is an asynchronous means of including modules, where as require is synchronous. CommonJS does not support async in the root of a module, import itself does exist in CommonJS, just not in the root level of a module (file). If you create an async function, you can all and await import from inside of it. ESM will handle the root level async imports for you, and provide a whole realm of future features going forward. ESM can consume and use CommonJS modules, but CommonJS cannot consume ESM modules, it's a one way street. A module either has to explicitly output both an ESM and a CommonJS output, and be configured in such a way that it exposes both in a resolvable fashion. In some cases people use a simple wrapper to achieve this, but it does not come without it's pains. This is mostly only an issue if you're building something with the intention of publishing it to npm where it will be consumed by a wider audience. Because whether or not you support both impacts who can consume your API. The reason you get this error: Cannot use import statement outside of a module Is because the backend project where you're using import is currently set to be CommonJS. You should add: { ... type: "module" ... } to your package.json in your backend project. If you'd like to see a TypeScript project configured to support both commonjs and ESM, without relying on any additional dependencies to do so, you can see my csrf-csrf project here, which has a package.json and a tsconfig, and some scripts, configured to output and publish a module to npm which natively supports both. More on reddit.com
🌐 r/node
9
27
December 9, 2022
🌐
Reddit
reddit.com › r/learnjavascript › what are modules
r/learnjavascript on Reddit: What are modules
August 7, 2024 -

Is a module just a JavaScript library?

Everything seems so mysterious about them. Every tutorial talks about theyre history and ES history and what not. Talks about systems for handling modules, but never about what a module is.

They say a module allows a JavaScript code to be accessed, but every code in every file is always accessible, every mp3 file is accessible and playable, every C file is accessible, compilable, readable ... (Unlees its got root privilege restrictions)

Modules vs Functions in Pseudocode Jun 30, 2016
r/learnprogramming
10y ago
The 5 Essential Elements of Modular Software Design Jan 28, 2020
r/SoftwareEngineering
6y ago
Best way to think about modules in JavaScript? Nov 23, 2023
r/learnjavascript
2y ago
What is the exact difference between modules and objects? Jun 15, 2020
r/learnprogramming
6y ago
More results from reddit.com
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › modules
Modules, introduction
October 14, 2022 - As our application grows bigger, we want to split it into multiple files, so called “modules”. A module may contain a class or a library of functions for a specific purpose. For a long time, JavaScript existed without a language-level module syntax.
🌐
Eloquent JavaScript
eloquentjavascript.net › 10_modules.html
Modules :: Eloquent JavaScript
Since ECMAScript 2015, JavaScript supports two different types of programs. Scripts behave in the old way: their bindings are defined in the global scope, and they have no way to directly reference other scripts. Modules get their own separate scope and support the import and export keywords, which aren’t available in scripts, to declare their dependencies and interface.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-modules
JavaScript Modules - GeeksforGeeks
A JavaScript module is a small piece of code that can be used in different parts of your program. It helps break down big projects into smaller, more manageable sections, each focused on a specific task.
Published   July 31, 2025
Find elsewhere
🌐
V8
v8.dev › features › modules
JavaScript modules · V8
JS modules (also known as “ES modules” or “ECMAScript modules”) are a major new feature, or rather a collection of new features. You may have used a userland JavaScript module system in the past. Maybe you used CommonJS like in Node.js, or maybe AMD, or maybe something else.
🌐
Medium
medium.com › @sshiwangi770 › javascript-modules-the-backbone-of-modern-js-development-819f70af0d28
JavaScript Modules: The Backbone of Modern JS Development | by Shiwangi Kumari | Medium
February 25, 2025 - If you’re building anything beyond a basic script, modules are essential. They: Prevent name conflicts by keeping code isolated. Improve maintainability by allowing smaller, focused files. Boost performance by loading only what’s needed. Enable code reuse across multiple projects. In short, JavaScript modules are the backbone of modern development.
🌐
iO tech_hub
techhub.iodigital.com › articles › javascript-module-systems
JavaScript Module Systems
October 11, 2023 - In this article, we are going to ... JavaScript, a module system allows developers to organize code into reusable pieces or components, which can be imported and used in other application parts....
🌐
Coherent Labs
coherent-labs.com › home › javascript modules
JavaScript Modules are part of our ES6 series tutorial from Coherent Labs
December 13, 2017 - Essentially, modules in ES6 are files that contain JavaScript code, that automatically runs in strict mode (and there is no way to opt-out). That code may contain declarations as variable declarations, function declarations, class declarations, etc.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_modules.htm
JavaScript - Modules
A module in JavaScript is a single file containing a JavaScript code or script. Rather than adding the code for the whole application in a single file, we can break down the code and create separate files for the code having the same
🌐
W3Schools
w3schools.com › nodejs › nodejs_modules_esm.asp
Node.js ES Modules
ES Modules (ESM) is the official standard format for packaging JavaScript code for reuse.
🌐
Yashints
yashints.dev › blog › 2019 › 08 › 27 › js-modules
Yas Adel Mehraban (Yashints) | JavaScript modules, the good, the bad and the ugly 🧐
August 27, 2019 - We had a look at before and after ES6 Modules and saw some of the differences in syntax. We saw the power of the module system in JavaScript and its benefits when it comes to using it in larger code bases.
🌐
DEV Community
dev.to › sojinsamuel › a-complete-beginners-guide-to-javascript-modules-2022-noobs-are-welcome-4lhm
A Complete Beginners Guide to JavaScript Modules (2023 Noobs are Welcome) - DEV Community
January 25, 2023 - The Module pattern is used to imitate the notion of classes (since JavaScript does not natively support classes) so that we may contain both public and private functions and variables inside a single object, similar to how classes are used in other programming languages such as Java or Python.
🌐
Newline
newline.co › courses › creating-react-libraries-from-scratch › what-are-js-modules
A Brief Guide to JavaScript Modules and What They Do - 4.2 | newline
March 22, 2021 - [00:36 - 01:20] Only recently was ESM or the ECMAScript modules introduced as a core JavaScript feature and a final standard for modules. Common JS modules were created to provide synchronous module handling, primarily in Node.js. When a file needs to make code public, the common JS uses module exports syntax.
🌐
DEV Community
dev.to › nick_baughan_f9ec9942a306 › javascript-modules-an-introduction-4e44
JavaScript Modules: An Introduction - DEV Community
March 29, 2025 - JavaScript Modules or ES6 Modules, while not immediately implemented, is today the standard in all browsers and NodeJS.
🌐
Medium
medium.com › @manasamancharla11 › understanding-javascript-modules-fba7f037fe49
Understanding JavaScript Modules | Medium
December 27, 2024 - JavaScript modules provide means to organize and structure your code. With modules it is easier to break down your code into small, reusable and maintainable pieces.