Node.js dgram: UDP datagram sockets
Answer: The node:dgram module provides an implementation of UDP datagram sockets. dgram.createSocket with udp4 creates a UDP socket. bind listens on a port. The message event delivers a received datagram, and the error event reports socket errors.
Examples
import dgram from 'node:dgram';
const server = dgram.createSocket('udp4');
server.on('message', (msg, rinfo) => {
console.log(msg.toString(), rinfo.address);
});
server.bind(41234);
Notes
The module is a stable implementation of UDP datagram sockets.
Reference list
Thedgram module implements UDP datagram sockets.createSocketcan construct a udp4 socket.Theexample binds the socket to port 41234.
See also
Claims
- id: C1 claim: The dgram module implements UDP datagram sockets. source: S1 evidence: "The node:dgram module provides an implementation of UDP datagram sockets"
- id: C2 claim: createSocket can construct a udp4 socket. source: S2 evidence: "const server = dgram.createSocket('udp4')"
- id: C3 claim: The example binds the socket to port 41234. source: S2 evidence: "server.bind(41234)"
Sources
- [S1] UDP/datagram sockets. Node.js docs. https://nodejs.org/api/dgram.html . License: MIT. Accessed 2026-11-18.
- [S2] dgram.md. Node.js. https://raw.githubusercontent.com/nodejs/node/main/doc/api/dgram.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js docs, UDP/datagram sockets; Node.js, dgram.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js docs, UDP/datagram sockets; Node.js, dgram.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "Node.js dgram: UDP datagram sockets." iinventedlight Library, iil:note:rm03m4k5, version of 2026-11-18. https://iinventedlight.com/library/notes/node-dgram/. License: CC-BY-4.0.
@misc{iil_note_rm03m4k5,
author = {{iinventedlight}},
title = {{Node.js dgram: UDP datagram sockets}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-dgram/},
note = {Permanent ID iil:note:rm03m4k5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- node-dgram.table.json (table; CC-BY-4.0)
- node-dgram.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-dgram.md.