diff --git a/doc/api/http.md b/doc/api/http.md index b9d2fe4320da..563fc0efcd33 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -6,8 +6,15 @@ -This module, containing both a client and server, can be imported via -`require('node:http')` (CommonJS) or `import * as http from 'node:http'` (ES module). +The `http` module provides utilities for building HTTP servers and clients. It can be accessed using: + +```mjs +import * as http from 'node:http'; +``` + +```cjs +const http = require('node:http'); +``` The HTTP interfaces in Node.js are designed to support many features of the protocol which have been traditionally difficult to use. diff --git a/doc/api/module.md b/doc/api/module.md index 956b10942ba3..35628f8a80ce 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -6,13 +6,17 @@ added: v0.3.7 --> -## The `Module` object +The `node:module` module provides utilities for interacting with the module system in Node.js. +It allows you to work with CommonJS and ECMAScript modules, manage module resolution, +and access built-in modules. It can be accessed using: -* Type: {Object} +```mjs +import module from 'node:module'; +``` -Provides general utility methods when interacting with instances of -`Module`, the [`module`][] variable often seen in [CommonJS][] modules. Accessed -via `import 'node:module'` or `require('node:module')`. +```cjs +const module = require('node:module'); +``` ### `module.builtinModules` @@ -2070,7 +2074,6 @@ returned object contains the following keys: [`module.getCompileCacheDir()`]: #modulegetcompilecachedir [`module.registerHooks()`]: #moduleregisterhooksoptions [`module.setSourceMapsSupport()`]: #modulesetsourcemapssupportenabled-options -[`module`]: #the-module-object [`os.tmpdir()`]: os.md#ostmpdir [`register`]: #moduleregisterspecifier-parenturl-options [`util.TextDecoder`]: util.md#class-utiltextdecoder diff --git a/doc/api/punycode.md b/doc/api/punycode.md index 43ea7d518fc3..b0d83079ff22 100644 --- a/doc/api/punycode.md +++ b/doc/api/punycode.md @@ -20,7 +20,11 @@ encoding, see [`url.domainToASCII`][] or, more generally, the The `punycode` module is a bundled version of the [Punycode.js][] module. It can be accessed using: -```js +```mjs +import punycode from 'node:punycode'; +``` + +```cjs const punycode = require('node:punycode'); ``` diff --git a/doc/api/querystring.md b/doc/api/querystring.md index f7f45d57d927..687882bd8ea7 100644 --- a/doc/api/querystring.md +++ b/doc/api/querystring.md @@ -11,7 +11,11 @@ The `node:querystring` module provides utilities for parsing and formatting URL query strings. It can be accessed using: -```js +```mjs +import querystring from 'node:querystring'; +``` + +```cjs const querystring = require('node:querystring'); ``` diff --git a/doc/api/quic.md b/doc/api/quic.md index 7a52e4f72c1f..2adf27edf537 100644 --- a/doc/api/quic.md +++ b/doc/api/quic.md @@ -10,7 +10,7 @@ added: v23.8.0 -The 'node:quic' module provides an implementation of the QUIC protocol. +The `node:quic` module provides an implementation of the QUIC protocol. To access it, start Node.js with the `--experimental-quic` option and: ```mjs diff --git a/doc/api/stream.md b/doc/api/stream.md index 3b2308851f0d..471c7998cf5d 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -18,7 +18,11 @@ Streams can be readable, writable, or both. All streams are instances of To access the `node:stream` module: -```js +```mjs +import stream from 'node:stream'; +``` + +```cjs const stream = require('node:stream'); ``` diff --git a/doc/api/tty.md b/doc/api/tty.md index 03f86cd66052..4a278407f913 100644 --- a/doc/api/tty.md +++ b/doc/api/tty.md @@ -10,7 +10,11 @@ The `node:tty` module provides the `tty.ReadStream` and `tty.WriteStream` classes. In most cases, it will not be necessary or possible to use this module directly. However, it can be accessed using: -```js +```mjs +import tty from 'node:tty'; +``` + +```cjs const tty = require('node:tty'); ``` diff --git a/doc/api/webcrypto.md b/doc/api/webcrypto.md index 562bdb37c2af..6aa5fa1f0e68 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -88,7 +88,24 @@ Node.js provides an implementation of the [Web Crypto API][] standard. Use `globalThis.crypto` or `require('node:crypto').webcrypto` to access this module. -```js +```mjs +const { subtle } = globalThis.crypto; + +const key = await subtle.generateKey({ + name: 'HMAC', + hash: 'SHA-256', + length: 256, +}, true, ['sign', 'verify']); + +const enc = new TextEncoder(); +const message = enc.encode('I love cupcakes'); + +const digest = await subtle.sign({ + name: 'HMAC', +}, key, message); +``` + +```cjs const { subtle } = globalThis.crypto; (async function() { diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md index 45e87152b86b..f74224d1efe1 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -38,17 +38,9 @@ This example creates a simple `ReadableStream` that pushes the current is used to read the data from the stream. ```mjs -import { - ReadableStream, -} from 'node:stream/web'; - -import { - setInterval as every, -} from 'node:timers/promises'; - -import { - performance, -} from 'node:perf_hooks'; +import { ReadableStream } from 'node:stream/web'; +import { setInterval as every } from 'node:timers/promises'; +import { performance } from 'node:perf_hooks'; const SECOND = 1000; @@ -64,17 +56,9 @@ for await (const value of stream) ``` ```cjs -const { - ReadableStream, -} = require('node:stream/web'); - -const { - setInterval: every, -} = require('node:timers/promises'); - -const { - performance, -} = require('node:perf_hooks'); +const { ReadableStream } = require('node:stream/web'); +const { setInterval: every } = require('node:timers/promises'); +const { performance } = require('node:perf_hooks'); const SECOND = 1000;