Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/api/packages.md')
-rw-r--r--doc/api/packages.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md
index bd5fbe150b5..02884be8627 100644
--- a/doc/api/packages.md
+++ b/doc/api/packages.md
@@ -709,6 +709,32 @@ and in a CommonJS one. For example, this code will also work:
const { something } = require('a-package/foo'); // Loads from ./foo.js.
```
+Finally, self-referencing also works with scoped packages. For example, this
+code will also work:
+
+```json
+// package.json
+{
+ "name": "@my/package",
+ "exports": "./index.js"
+}
+```
+
+```js
+// ./index.js
+module.exports = 42;
+```
+
+```js
+// ./other.js
+console.log(require('@my/package'));
+```
+
+```console
+$ node other.js
+42
+```
+
## Dual CommonJS/ES module packages
Prior to the introduction of support for ES modules in Node.js, it was a common