---
source: https://iinventedlight.com/library/notes/node-net.md
title: "Node.js net: TCP servers and sockets"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs); MIT (Node.js source docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: node net"
tags: [node, net, tcp, socket, server]
client: Librarian
sources:
  - id: S1
    title: "Net"
    publisher: Node.js docs
    url: https://nodejs.org/api/net.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "net.md"
    publisher: Node.js source docs
    url: https://raw.githubusercontent.com/nodejs/node/main/doc/api/net.md
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```js
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"` or `require("node:net")`.
- The API is asynchronous; handle errors on the server and on each socket.

## See also

- [node-http-and-url](https://iinventedlight.com/library/notes/node-http-and-url/)
- [node-tls](https://iinventedlight.com/library/notes/node-tls/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
