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/dgram.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/dgram.md')
-rw-r--r-- | doc/api/dgram.md | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/doc/api/dgram.md b/doc/api/dgram.md index a67ee8e2f41..f9e9b6b8745 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -8,10 +8,10 @@ <!-- source_link=lib/dgram.js --> -The `dgram` module provides an implementation of UDP datagram sockets. +The `node:dgram` module provides an implementation of UDP datagram sockets. ```mjs -import dgram from 'dgram'; +import dgram from 'node:dgram'; const server = dgram.createSocket('udp4'); @@ -34,7 +34,7 @@ server.bind(41234); ``` ```cjs -const dgram = require('dgram'); +const dgram = require('node:dgram'); const server = dgram.createSocket('udp4'); server.on('error', (err) => { @@ -154,8 +154,8 @@ When sharing a UDP socket across multiple `cluster` workers, the `EADDRINUSE` error will occur: ```mjs -import cluster from 'cluster'; -import dgram from 'dgram'; +import cluster from 'node:cluster'; +import dgram from 'node:dgram'; if (cluster.isPrimary) { cluster.fork(); // Works ok. @@ -169,8 +169,8 @@ if (cluster.isPrimary) { ``` ```cjs -const cluster = require('cluster'); -const dgram = require('dgram'); +const cluster = require('node:cluster'); +const dgram = require('node:dgram'); if (cluster.isPrimary) { cluster.fork(); // Works ok. @@ -256,7 +256,7 @@ attempting to bind with a closed socket), an [`Error`][] may be thrown. Example of a UDP server listening on port 41234: ```mjs -import dgram from 'dgram'; +import dgram from 'node:dgram'; const server = dgram.createSocket('udp4'); @@ -279,7 +279,7 @@ server.bind(41234); ``` ```cjs -const dgram = require('dgram'); +const dgram = require('node:dgram'); const server = dgram.createSocket('udp4'); server.on('error', (err) => { @@ -569,8 +569,8 @@ This method throws [`ERR_SOCKET_BAD_PORT`][] if called on an unbound socket. Example of sending a UDP packet to a port on `localhost`; ```mjs -import dgram from 'dgram'; -import { Buffer } from 'buffer'; +import dgram from 'node:dgram'; +import { Buffer } from 'node:buffer'; const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); @@ -580,8 +580,8 @@ client.send(message, 41234, 'localhost', (err) => { ``` ```cjs -const dgram = require('dgram'); -const { Buffer } = require('buffer'); +const dgram = require('node:dgram'); +const { Buffer } = require('node:buffer'); const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); @@ -594,8 +594,8 @@ Example of sending a UDP packet composed of multiple buffers to a port on `127.0.0.1`; ```mjs -import dgram from 'dgram'; -import { Buffer } from 'buffer'; +import dgram from 'node:dgram'; +import { Buffer } from 'node:buffer'; const buf1 = Buffer.from('Some '); const buf2 = Buffer.from('bytes'); @@ -606,8 +606,8 @@ client.send([buf1, buf2], 41234, (err) => { ``` ```cjs -const dgram = require('dgram'); -const { Buffer } = require('buffer'); +const dgram = require('node:dgram'); +const { Buffer } = require('node:buffer'); const buf1 = Buffer.from('Some '); const buf2 = Buffer.from('bytes'); @@ -626,8 +626,8 @@ Example of sending a UDP packet using a socket connected to a port on `localhost`: ```mjs -import dgram from 'dgram'; -import { Buffer } from 'buffer'; +import dgram from 'node:dgram'; +import { Buffer } from 'node:buffer'; const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); @@ -639,8 +639,8 @@ client.connect(41234, 'localhost', (err) => { ``` ```cjs -const dgram = require('dgram'); -const { Buffer } = require('buffer'); +const dgram = require('node:dgram'); +const { Buffer } = require('node:buffer'); const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); @@ -868,7 +868,7 @@ Calling `socket.unref()` multiple times will have no addition effect. The `socket.unref()` method returns a reference to the socket so calls can be chained. -## `dgram` module functions +## `node:dgram` module functions ### `dgram.createSocket(options[, callback])` |