diff --git a/doc/api/packages.md b/doc/api/packages.md index bd5fbe150b544b..02884be862759c 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