Skip to content

Commit 0cb1bca

Browse files
aduh95juanarbol
authored andcommitted
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: #42752 Fixes: #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>
1 parent e638271 commit 0cb1bca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2293
-1746
lines changed

doc/api/assert.md

+83-83
Large diffs are not rendered by default.

doc/api/async_context.md

+29-29
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ or any other asynchronous duration. It is similar to thread-local storage
1515
in other languages.
1616

1717
The `AsyncLocalStorage` and `AsyncResource` classes are part of the
18-
`async_hooks` module:
18+
`node:async_hooks` module:
1919

2020
```mjs
21-
import { AsyncLocalStorage, AsyncResource } from 'async_hooks';
21+
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
2222
```
2323

2424
```cjs
25-
const { AsyncLocalStorage, AsyncResource } = require('async_hooks');
25+
const { AsyncLocalStorage, AsyncResource } = require('node:async_hooks');
2626
```
2727

2828
## Class: `AsyncLocalStorage`
@@ -39,18 +39,18 @@ changes:
3939

4040
This class creates stores that stay coherent through asynchronous operations.
4141

42-
While you can create your own implementation on top of the `async_hooks` module,
43-
`AsyncLocalStorage` should be preferred as it is a performant and memory safe
44-
implementation that involves significant optimizations that are non-obvious to
45-
implement.
42+
While you can create your own implementation on top of the `node:async_hooks`
43+
module, `AsyncLocalStorage` should be preferred as it is a performant and memory
44+
safe implementation that involves significant optimizations that are non-obvious
45+
to implement.
4646

4747
The following example uses `AsyncLocalStorage` to build a simple logger
4848
that assigns IDs to incoming HTTP requests and includes them in messages
4949
logged within each request.
5050

5151
```mjs
52-
import http from 'http';
53-
import { AsyncLocalStorage } from 'async_hooks';
52+
import http from 'node:http';
53+
import { AsyncLocalStorage } from 'node:async_hooks';
5454

5555
const asyncLocalStorage = new AsyncLocalStorage();
5656

@@ -81,8 +81,8 @@ http.get('http://localhost:8080');
8181
```
8282

8383
```cjs
84-
const http = require('http');
85-
const { AsyncLocalStorage } = require('async_hooks');
84+
const http = require('node:http');
85+
const { AsyncLocalStorage } = require('node:async_hooks');
8686

8787
const asyncLocalStorage = new AsyncLocalStorage();
8888

@@ -348,7 +348,7 @@ The `init` hook will trigger when an `AsyncResource` is instantiated.
348348
The following is an overview of the `AsyncResource` API.
349349

350350
```mjs
351-
import { AsyncResource, executionAsyncId } from 'async_hooks';
351+
import { AsyncResource, executionAsyncId } from 'node:async_hooks';
352352

353353
// AsyncResource() is meant to be extended. Instantiating a
354354
// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
@@ -376,7 +376,7 @@ asyncResource.triggerAsyncId();
376376
```
377377

378378
```cjs
379-
const { AsyncResource, executionAsyncId } = require('async_hooks');
379+
const { AsyncResource, executionAsyncId } = require('node:async_hooks');
380380

381381
// AsyncResource() is meant to be extended. Instantiating a
382382
// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
@@ -535,14 +535,14 @@ Assuming that the task is adding two numbers, using a file named
535535
`task_processor.js` with the following content:
536536

537537
```mjs
538-
import { parentPort } from 'worker_threads';
538+
import { parentPort } from 'node:worker_threads';
539539
parentPort.on('message', (task) => {
540540
parentPort.postMessage(task.a + task.b);
541541
});
542542
```
543543

544544
```cjs
545-
const { parentPort } = require('worker_threads');
545+
const { parentPort } = require('node:worker_threads');
546546
parentPort.on('message', (task) => {
547547
parentPort.postMessage(task.a + task.b);
548548
});
@@ -551,10 +551,10 @@ parentPort.on('message', (task) => {
551551
a Worker pool around it could use the following structure:
552552

553553
```mjs
554-
import { AsyncResource } from 'async_hooks';
555-
import { EventEmitter } from 'events';
556-
import path from 'path';
557-
import { Worker } from 'worker_threads';
554+
import { AsyncResource } from 'node:async_hooks';
555+
import { EventEmitter } from 'node:events';
556+
import path from 'node:path';
557+
import { Worker } from 'node:worker_threads';
558558

559559
const kTaskInfo = Symbol('kTaskInfo');
560560
const kWorkerFreedEvent = Symbol('kWorkerFreedEvent');
@@ -639,10 +639,10 @@ export default class WorkerPool extends EventEmitter {
639639
```
640640
641641
```cjs
642-
const { AsyncResource } = require('async_hooks');
643-
const { EventEmitter } = require('events');
644-
const path = require('path');
645-
const { Worker } = require('worker_threads');
642+
const { AsyncResource } = require('node:async_hooks');
643+
const { EventEmitter } = require('node:events');
644+
const path = require('node:path');
645+
const { Worker } = require('node:worker_threads');
646646

647647
const kTaskInfo = Symbol('kTaskInfo');
648648
const kWorkerFreedEvent = Symbol('kWorkerFreedEvent');
@@ -738,7 +738,7 @@ This pool could be used as follows:
738738
739739
```mjs
740740
import WorkerPool from './worker_pool.js';
741-
import os from 'os';
741+
import os from 'node:os';
742742

743743
const pool = new WorkerPool(os.cpus().length);
744744

@@ -754,7 +754,7 @@ for (let i = 0; i < 10; i++) {
754754
755755
```cjs
756756
const WorkerPool = require('./worker_pool.js');
757-
const os = require('os');
757+
const os = require('node:os');
758758

759759
const pool = new WorkerPool(os.cpus().length);
760760

@@ -779,8 +779,8 @@ associate an event listener with the correct execution context. The same
779779
approach can be applied to a [`Stream`][] or a similar event-driven class.
780780
781781
```mjs
782-
import { createServer } from 'http';
783-
import { AsyncResource, executionAsyncId } from 'async_hooks';
782+
import { createServer } from 'node:http';
783+
import { AsyncResource, executionAsyncId } from 'node:async_hooks';
784784

785785
const server = createServer((req, res) => {
786786
req.on('close', AsyncResource.bind(() => {
@@ -794,8 +794,8 @@ const server = createServer((req, res) => {
794794
```
795795
796796
```cjs
797-
const { createServer } = require('http');
798-
const { AsyncResource, executionAsyncId } = require('async_hooks');
797+
const { createServer } = require('node:http');
798+
const { AsyncResource, executionAsyncId } = require('node:async_hooks');
799799

800800
const server = createServer((req, res) => {
801801
req.on('close', AsyncResource.bind(() => {

0 commit comments

Comments
 (0)