docs: add import syntax with module example (#1831)
Specify `import` alongside `require()` syntax
anthumchris committed
Jan 5, 2026 at 11:32 UTC
22f731c0da82abe7f3279ee78717b57e871a46e4
1 file changed
+11
-2
content/packages-and-modules/introduction-to-packages-and-modules/about-packages-and-modules.mdx
+11
-2
@@ -43,13 +43,22 @@ Installing any package directly from git will not install [git submodules](https
43
44
## About modules
45
46
-A **module** is any file or directory in the `node_modules` directory that can be loaded by the Node.js `require()` function.
46
+A **module** is any file or directory in the `node_modules` directory that can be loaded by the Node.js `require()` or `import` syntax.
47
48
To be loaded by the Node.js `require()` function, a module must be one of the following:
49
50
- A folder with a `package.json` file containing a `"main"` field.
51
- A JavaScript file.
52
53
+To use the `import` syntax, a module should also include `"type": "module"` in its `package.json` file:
54
+
55
+```json
56
+{
57
+ "name": "my-package",
58
+ "type": "module"
59
+}
60
+```
61
+
62
<Note>
63
64
**Note:** Since modules are not required to have a `package.json` file, not all modules are packages. Only modules that have a `package.json` file are also packages.
@@ -59,7 +68,7 @@ To be loaded by the Node.js `require()` function, a module must be one of the fo
68
In the context of a Node program, the `module` is also the thing that was loaded _from_ a file. For example, in the following program:
69
70
```
62
-var req = require('request')
71
+const req = require('request')
72
```
73
74
The `req` variable refers to the `request` module returned by the `require()` function.