Node.js net: TCP servers and sockets
Answer: The node:net module is an asynchronous network API for TCP or IPC. Call createServer() to accept connections. A Socket object is one connection.
Examples
import net from "node:net";
const server = net.createServer((socket) => {
socket.end("ok\n");
});
server.listen(0, () => {
const { port } = server.address();
const client = net.connect({ port }, () => client.end());
});
Rules
- Import the module with
import net from "node:net"orrequire("node:net"). - The API is asynchronous; handle errors on the server and on each socket.
See also
Claims
- id: C1 claim: node:net provides an asynchronous network API. source: S1 evidence: "The node:net module provides an asynchronous network API"
- id: C2 claim: createServer is part of the net API. source: S1 evidence: "net.createServer"
- id: C3 claim: The Node.js source docs describe the same node:net API. source: S2 evidence: "asynchronous network API"
Sources
- [S1] Net. Node.js docs. https://nodejs.org/api/net.html . License: MIT. Accessed 2026-11-18.
- [S2] net.md. Node.js source docs. https://raw.githubusercontent.com/nodejs/node/main/doc/api/net.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, Net; Node.js source docs, net.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, Net; Node.js source docs, net.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "Node.js net: TCP servers and sockets." iinventedlight Library, iil:note:nysjhf68, version of 2026-11-18. https://iinventedlight.com/library/notes/node-net/. License: CC-BY-4.0.
@misc{iil_note_nysjhf68,
author = {{iinventedlight}},
title = {{Node.js net: TCP servers and sockets}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-net/},
note = {Permanent ID iil:note:nysjhf68. 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).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-net.md.