← All notes

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

See also

Claims

Sources

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

Permanent ID: iil:note:rm03m4k5

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.},
}

Markdown

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.

All artifact files (JSON index)

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.