Skip to content

node:net

How Elide supports Node's net module: TCP and Unix-domain servers and clients, BlockList, SocketAddress and isIP match Node, with sandbox network flags.

On this page

node:net matches Node’s net for TCP and Unix-domain servers and clients, BlockList, SocketAddress, and the isIP helpers; --allow-net and --deny-net apply under the sandbox.

Example

js
// net.mjs
import net from "node:net";

const server = net.createServer((socket) => socket.pipe(socket));
server.listen(0, "127.0.0.1", () => {
  const client = net.connect(server.address().port, "127.0.0.1", () => client.end("ping"));
  client.on("data", (data) => console.log("echo:", data.toString()));
  client.on("close", () => server.close(() => console.log("server closed")));
});
console.log(net.isIP("::1"), net.isIPv4("127.0.0.1"));
utf-8 · js · Lines: 10

elide run net.mjs prints:

text
6 true
echo: ping
server closed
utf-8 · text · Lines: 3

Reference

Status: Partial · Not measured

net exports

BlockList, Server, Socket, SocketAddress, Stream, connect, createConnection, createServer, getDefaultAutoSelectFamily, getDefaultAutoSelectFamilyAttemptTimeout, isIP, isIPv4, isIPv6, setDefaultAutoSelectFamily, setDefaultAutoSelectFamilyAttemptTimeout

Not implemented

BoundSocket.

Was this page helpful?