diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-04-20 11:23:41 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-04-28 07:56:14 +0300 |
commit | 3d65a3b13e61f136dc09027aa12473c2b3003725 (patch) | |
tree | 012259a22a22fec5325afd386bbae62e3293a09f /doc/api/esm.md | |
parent | 46c880b99b4a74c3a7c99fdd824bf9ce22333987 (diff) |
doc: add `node:` prefix for all core modules
Some core modules can be loaded with or without the `node:` prefix.
Using the prefix disambiguates which specifiers refer to core modules.
This commit updates the docs to use the prefix everywhere a core module
is referenced.
PR-URL: https://github.com/nodejs/node/pull/42752
Fixes: https://github.com/nodejs/node/issues/38343
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Diffstat (limited to 'doc/api/esm.md')
-rw-r--r-- | doc/api/esm.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md index bea63a9d20c..e531a61416e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -116,7 +116,7 @@ This section was moved to [Modules: Packages](packages.md). ### Terminology The _specifier_ of an `import` statement is the string after the `from` keyword, -e.g. `'path'` in `import { sep } from 'path'`. Specifiers are also used in +e.g. `'path'` in `import { sep } from 'node:path'`. Specifiers are also used in `export from` statements, and as the argument to an `import()` expression. There are three types of specifiers: @@ -260,12 +260,12 @@ exports. Named exports of builtin modules are updated only by calling [`module.syncBuiltinESMExports()`][]. ```js -import EventEmitter from 'events'; +import EventEmitter from 'node:events'; const e = new EventEmitter(); ``` ```js -import { readFile } from 'fs'; +import { readFile } from 'node:fs'; readFile('./foo.txt', (err, source) => { if (err) { console.error(err); @@ -276,9 +276,9 @@ readFile('./foo.txt', (err, source) => { ``` ```js -import fs, { readFileSync } from 'fs'; -import { syncBuiltinESMExports } from 'module'; -import { Buffer } from 'buffer'; +import fs, { readFileSync } from 'node:fs'; +import { syncBuiltinESMExports } from 'node:module'; +import { Buffer } from 'node:buffer'; fs.readFileSync = () => Buffer.from('Hello, ESM'); syncBuiltinESMExports(); @@ -308,7 +308,7 @@ current module file. This enables useful patterns such as relative file loading: ```js -import { readFileSync } from 'fs'; +import { readFileSync } from 'node:fs'; const buffer = readFileSync(new URL('./data.proto', import.meta.url)); ``` @@ -592,8 +592,8 @@ If a top level `await` expression never resolves, the `node` process will exit with a `13` [status code][]. ```js -import { spawn } from 'child_process'; -import { execPath } from 'process'; +import { spawn } from 'node:child_process'; +import { execPath } from 'node:process'; spawn(execPath, [ '--input-type=module', @@ -646,7 +646,7 @@ references to the local dependencies: ```mjs // file.mjs -import worker_threads from 'worker_threads'; +import worker_threads from 'node:worker_threads'; import { configure, resize } from 'https://example.com/imagelib.mjs'; configure({ worker_threads }); ``` @@ -948,7 +948,7 @@ and there is no security. ```js // https-loader.mjs -import { get } from 'https'; +import { get } from 'node:https'; export function resolve(specifier, context, defaultResolve) { const { parentURL = null } = context; @@ -1118,7 +1118,7 @@ async function getPackageType(url) { import { scream } from './scream.coffee' console.log scream 'hello, world' -import { version } from 'process' +import { version } from 'node:process' console.log "Brought to you by Node.js version #{version}" ``` |