Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

<!-- source_link=lib/http.js -->

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.
Expand Down
15 changes: 9 additions & 6 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion doc/api/punycode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

Expand Down
6 changes: 5 additions & 1 deletion doc/api/querystring.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

Expand Down
2 changes: 1 addition & 1 deletion doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ added: v23.8.0

<!-- source_link=lib/quic.js -->

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
Expand Down
6 changes: 5 additions & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

Expand Down
6 changes: 5 additions & 1 deletion doc/api/tty.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

Expand Down
19 changes: 18 additions & 1 deletion doc/api/webcrypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
28 changes: 6 additions & 22 deletions doc/api/webstreams.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
Loading