summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2020-05-14 14:56:10 -0600
committerGitHub <noreply@github.com>2020-05-14 14:56:10 -0600
commit085e97d63c35449758a3c62da0674a03ba9e9912 (patch)
treec0368a48438e9dd24af9c232e3c8bd0ac8fff2d4
parent47804933012841f2dc90626bdcc161adf34569a5 (diff)
downloadnode-new-085e97d63c35449758a3c62da0674a03ba9e9912.tar.gz
doc: fix esm extension example with type module
-rw-r--r--doc/api/esm.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md
index f3a34e7d46..1461379f6a 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -13,6 +13,19 @@ ECMAScript modules are [the official standard format][] to package JavaScript
code for reuse. Modules are defined using a variety of [`import`][] and
[`export`][] statements.
+First, to enable modules in Node.js for `.js` extensions, ensure there is a
+`package.json` file in the root of the project with `"type": "module"` set:
+
+```js
+// package.json
+{
+ "name": "app",
+ "type": "module"
+}
+```
+
+> An alternative to setting `"type": "module" is to use the `.mjs` extension.
+
The following example of an ES module exports a function:
```js