Node.js module
net
The 'node:net' module provides an asynchronous network API for creating TCP servers and clients. It exposes Socket and Server classes for handling raw network connections.
Works in Bun · notes
Core TCP socket functionality works. The SocketAddress class is implemented internally but not exposed. BlockList exists but is currently a no-op.
Functions 10
- net.connect()
Aliases to createConnection.
- net.createConnection()
A factory function, which creates a new Socket, immediately initiates connection with
socket.connect(), then returns thenet.Socketthat starts the connection. - net.createServer()
Creates a new TCP or
IPCserver. - net.getDefaultAutoSelectFamily()
Gets the current default value of the
autoSelectFamilyoption ofsocket.connect(options). - net.getDefaultAutoSelectFamilyAttemptTimeout()
Gets the current default value of the
autoSelectFamilyAttemptTimeoutoption ofsocket.connect(options). - net.isIP()
Returns
6ifinputis an IPv6 address. - net.isIPv4()
Returns
trueifinputis an IPv4 address in dot-decimal notation with no leading zeroes. - net.isIPv6()
Returns
trueifinputis an IPv6 address. - net.setDefaultAutoSelectFamily()
Sets the default value of the
autoSelectFamilyoption ofsocket.connect(options). - net.setDefaultAutoSelectFamilyAttemptTimeout()
Sets the default value of the
autoSelectFamilyAttemptTimeoutoption ofsocket.connect(options).
Classes 4
- class net.BlockList
The
BlockListobject can be used with some network APIs to specify rules for disabling inbound or outbound access to specific IP addresses, IP ranges, or - class net.Server
This class is used to create a TCP or
IPCserver. - class net.Socket
This class is an abstraction of a TCP socket or a streaming
IPCendpoint (uses named pipes on Windows, and Unix domain sockets otherwise). - class net.SocketAddress
Interfaces 13
- interface AddressInfo
- interface DropArgument
- interface IpcNetConnectOpts
- interface IpcSocketConnectOpts
- interface ListenOptions
- interface OnReadOpts
- interface ServerEventMap
- interface ServerOpts
- interface SocketAddressInitOptions
- interface SocketConstructorOpts
- interface SocketEventMap
- interface TcpNetConnectOpts
- interface TcpSocketConnectOpts