{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"net","path":"/net","type":"module","module":"net","title":"Net","introducedIn":"v0.10.0","sourceLink":{"path":"lib/net.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/net.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node:net` module provides an asynchronous network API for creating stream-based\nTCP or [IPC](#ipc-support) servers ([`net.createServer()`](#netcreateserveroptions-connectionlistener)) and clients\n([`net.createConnection()`](#netcreateconnection)).\n\nIt can be accessed using:\n\n```mjs\nimport net from 'node:net';\n```\n\n```cjs\nconst net = require('node:net');\n```","summary":"The `node:net` module provides an asynchronous network API for creating stream-based TCP or IPC servers (`net.createServer()`) and clients (`net.createConnection()`).","examples":[{"language":"mjs","displayName":null,"code":"import net from 'node:net';"},{"language":"cjs","displayName":null,"code":"const net = require('node:net');"}],"children":[{"kind":"section","id":"ipc-support","name":"IPC support","title":"IPC support","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.8.0"],"prUrl":"https://github.com/nodejs/node/pull/49667","commit":null,"description":"Support binding to abstract Unix domain socket path like `\\0abstract`. We can bind '\\0' for Node.js `< v20.4.0`."}],"description":"The `node:net` module supports IPC with named pipes on Windows, and Unix domain\nsockets on other operating systems.","summary":"The `node:net` module supports IPC with named pipes on Windows, and Unix domain sockets on other operating systems.","examples":[],"children":[{"kind":"section","id":"identifying-paths-for-ipc-connections","name":"Identifying paths for IPC connections","title":"Identifying paths for IPC connections","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"[`net.connect()`](#netconnect), [`net.createConnection()`](#netcreateconnection), [`server.listen()`](#serverlisten), and\n[`socket.connect()`](#socketconnect) take a `path` parameter to identify IPC endpoints.\n\nOn Unix, the local domain is also known as the Unix domain. The path is a\nfile system pathname. It will throw an error when the length of pathname is\ngreater than the length of `sizeof(sockaddr_un.sun_path)`. Typical values are\n107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates\nthe Unix domain socket, it will unlink the Unix domain socket as well. For\nexample, [`net.createServer()`](#netcreateserveroptions-connectionlistener) may create a Unix domain socket and\n[`server.close()`](#serverclosecallback) will unlink it. But if a user creates the Unix domain\nsocket outside of these abstractions, the user will need to remove it. The same\napplies when a Node.js API creates a Unix domain socket but the program then\ncrashes. In short, a Unix domain socket will be visible in the file system and\nwill persist until unlinked. On Linux, You can use Unix abstract socket by adding\n`\\0` to the beginning of the path, such as `\\0abstract`. The path to the Unix\nabstract socket is not visible in the file system and it will disappear automatically\nwhen all open references to the socket are closed.\n\nOn Windows, the local domain is implemented using a named pipe. The path *must*\nrefer to an entry in `\\\\?\\pipe\\` or `\\\\.\\pipe\\`. Any characters are permitted,\nbut the latter may do some processing of pipe names, such as resolving `..`\nsequences. Despite how it might look, the pipe namespace is flat. Pipes will\n*not persist*. They are removed when the last reference to them is closed.\nUnlike Unix domain sockets, Windows will close and remove the pipe when the\nowning process exits.\n\nJavaScript string escaping requires paths to be specified with extra backslash\nescaping such as:\n\n```js\nnet.createServer().listen(\n  path.join('\\\\\\\\?\\\\pipe', process.cwd(), 'myctl'));\n```","summary":"`net.connect()`, `net.createConnection()`, `server.listen()`, and `socket.connect()` take a `path` parameter to identify IPC endpoints.","examples":[{"language":"js","displayName":null,"code":"net.createServer().listen(\n  path.join('\\\\\\\\?\\\\pipe', process.cwd(), 'myctl'));"}],"children":[]}]},{"kind":"class","id":"class-netblocklist","name":"BlockList","title":"Class: `net.BlockList`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"The `BlockList` object can be used with some network APIs to specify rules for\ndisabling inbound or outbound access to specific IP addresses, IP ranges, or\nIP subnets.","summary":"The `BlockList` object can be used with some network APIs to specify rules for disabling inbound or outbound access to specific IP addresses, IP ranges, or IP subnets.","examples":[],"children":[{"kind":"method","id":"blocklistaddaddressaddress-type","name":"addAddress","title":"`blockList.addAddress(address[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"address","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"An IPv4 or IPv6 address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Adds a rule to block the given IP address.","summary":"Adds a rule to block the given IP address.","examples":[],"children":[]},{"kind":"method","id":"blocklistaddaddressesaddresses-type","name":"addAddresses","title":"`blockList.addAddresses(addresses[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"addresses","type":{"text":"string[] | net.SocketAddress[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":11,"end":28}]},"description":"An array of IPv4 or IPv6\naddresses.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Adds multiple address rules to the block list in a single operation.\nThis is more efficient than calling `blockList.addAddress()` repeatedly\nwhen adding a large number of individual addresses, as the addresses\nare inserted under a single internal lock acquisition.","summary":"Adds multiple address rules to the block list in a single operation. This is more efficient than calling `blockList.addAddress()` repeatedly when adding a large number of individual addresses, as the addresses are inserted under a single internal lock acquisition.","examples":[],"children":[]},{"kind":"method","id":"blocklistaddcidrcidr","name":"addCIDR","title":"`blockList.addCIDR(cidr)`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"cidr","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An IPv4 or IPv6 subnet in CIDR notation (e.g.\n`'10.0.0.0/8'` or `'2001:db8::/32'`).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Adds a subnet rule using CIDR notation. The address family is automatically\ndetected from the address (IPv6 if the address contains `':'`, IPv4\notherwise). This is equivalent to calling `blockList.addSubnet()` with\nthe parsed network address, prefix length, and family.","summary":"Adds a subnet rule using CIDR notation. The address family is automatically detected from the address (IPv6 if the address contains `':'`, IPv4 otherwise). This is equivalent to calling `blockList.addSubnet()` with the parsed network address, prefix length, and family.","examples":[],"children":[]},{"kind":"method","id":"blocklistaddcidrscidrs","name":"addCIDRs","title":"`blockList.addCIDRs(cidrs)`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"cidrs","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An array of IPv4 or IPv6 subnets in CIDR notation.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Adds multiple subnet rules using CIDR notation in a single call. The address\nfamily for each entry is automatically detected. This is equivalent to\ncalling `blockList.addCIDR()` for each element of the array.","summary":"Adds multiple subnet rules using CIDR notation in a single call. The address family for each entry is automatically detected. This is equivalent to calling `blockList.addCIDR()` for each element of the array.","examples":[],"children":[]},{"kind":"method","id":"blocklistaddrangestart-end-type","name":"addRange","title":"`blockList.addRange(start, end[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"start","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The starting IPv4 or IPv6 address in the\nrange.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"end","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The ending IPv4 or IPv6 address in the range.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Adds a rule to block a range of IP addresses from `start` (inclusive) to\n`end` (inclusive).","summary":"Adds a rule to block a range of IP addresses from `start` (inclusive) to `end` (inclusive).","examples":[],"children":[]},{"kind":"method","id":"blocklistaddsubnetnet-prefix-type","name":"addSubnet","title":"`blockList.addSubnet(net, prefix[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"net","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The network IPv4 or IPv6 address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"prefix","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of CIDR prefix bits. For IPv4, this\nmust be a value between `0` and `32`. For IPv6, this must be between\n`0` and `128`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Adds a rule to block a range of IP addresses specified as a subnet mask.","summary":"Adds a rule to block a range of IP addresses specified as a subnet mask.","examples":[],"children":[]},{"kind":"method","id":"blocklistcheckaddress-type","name":"check","title":"`blockList.check(address[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"address","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The IP address to check","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if the given IP address matches any of the rules added to the\n`BlockList`.\n\n```js\nconst blockList = new net.BlockList();\nblockList.addAddress('123.123.123.123');\nblockList.addRange('10.0.0.1', '10.0.0.10');\nblockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');\n\nconsole.log(blockList.check('123.123.123.123'));  // Prints: true\nconsole.log(blockList.check('10.0.0.3'));  // Prints: true\nconsole.log(blockList.check('222.111.111.222'));  // Prints: false\n\n// IPv6 notation for IPv4 addresses works:\nconsole.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true\nconsole.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true\n```","summary":"Returns `true` if the given IP address matches any of the rules added to the `BlockList`.","examples":[{"language":"js","displayName":null,"code":"const blockList = new net.BlockList();\nblockList.addAddress('123.123.123.123');\nblockList.addRange('10.0.0.1', '10.0.0.10');\nblockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');\n\nconsole.log(blockList.check('123.123.123.123'));  // Prints: true\nconsole.log(blockList.check('10.0.0.3'));  // Prints: true\nconsole.log(blockList.check('222.111.111.222'));  // Prints: false\n\n// IPv6 notation for IPv4 addresses works:\nconsole.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true\nconsole.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true"}],"children":[]},{"kind":"method","id":"blocklistclear","name":"clear","title":"`blockList.clear()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"<!--\nadded: v26.8.0\n-->\n\nClears all rules from the `BlockList`.","summary":"Clears all rules from the `BlockList`.","examples":[],"children":[]},{"kind":"method","id":"blocklistfromjsonvalue","name":"fromJSON","title":"`blockList.fromJSON(value)`","scope":"module","overloadOf":null,"stability":{"index":"1.2","description":"Release candidate"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"value","type":null,"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"<!-- YAML\nadded:\n - v24.5.0\n - v22.19.0\n-->\n\n```js\nconst blockList = new net.BlockList();\nconst data = [\n  'Subnet: IPv4 192.168.1.0/24',\n  'Address: IPv4 10.0.0.5',\n  'Range: IPv4 192.168.2.1-192.168.2.10',\n  'Range: IPv4 10.0.0.1-10.0.0.10',\n];\nblockList.fromJSON(data);\nblockList.fromJSON(JSON.stringify(data));\n```\n\n* `value` Blocklist.rules","summary":"","examples":[{"language":"js","displayName":null,"code":"const blockList = new net.BlockList();\nconst data = [\n  'Subnet: IPv4 192.168.1.0/24',\n  'Address: IPv4 10.0.0.5',\n  'Range: IPv4 192.168.2.1-192.168.2.10',\n  'Range: IPv4 10.0.0.1-10.0.0.10',\n];\nblockList.fromJSON(data);\nblockList.fromJSON(JSON.stringify(data));"}],"children":[]},{"kind":"method","id":"blocklistisblocklistvalue","name":"isBlockList","title":"`BlockList.isBlockList(value)`","scope":"module","overloadOf":null,"stability":null,"added":["v23.4.0","v22.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"Any JS value","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":null,"description":"`true` if the `value` is a `net.BlockList`."}},"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"blocklistprivate_ranges","name":"PRIVATE_RANGES","title":"`BlockList.PRIVATE_RANGES`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"A frozen array of CIDR strings representing private, loopback, and link-local\nIP address ranges. This can be passed to `blockList.addCIDRs()` to quickly\npopulate a blocklist with all non-routable address ranges.\n\nThe included ranges are:\n\n* `10.0.0.0/8` — RFC 1918 private IPv4\n* `172.16.0.0/12` — RFC 1918 private IPv4\n* `192.168.0.0/16` — RFC 1918 private IPv4\n* `127.0.0.0/8` — IPv4 loopback\n* `::1/128` — IPv6 loopback\n* `169.254.0.0/16` — IPv4 link-local\n* `fe80::/10` — IPv6 link-local\n* `fc00::/7` — IPv6 unique local (ULA)\n\n```js\nconst blockList = new net.BlockList();\nblockList.addCIDRs(net.BlockList.PRIVATE_RANGES);\n\nconsole.log(blockList.check('10.0.0.1'));      // Prints: true\nconsole.log(blockList.check('127.0.0.1'));     // Prints: true\nconsole.log(blockList.check('8.8.8.8'));       // Prints: false\n```","summary":"A frozen array of CIDR strings representing private, loopback, and link-local IP address ranges. This can be passed to `blockList.addCIDRs()` to quickly populate a blocklist with all non-routable address ranges.","examples":[{"language":"js","displayName":null,"code":"const blockList = new net.BlockList();\nblockList.addCIDRs(net.BlockList.PRIVATE_RANGES);\n\nconsole.log(blockList.check('10.0.0.1'));      // Prints: true\nconsole.log(blockList.check('127.0.0.1'));     // Prints: true\nconsole.log(blockList.check('8.8.8.8'));       // Prints: false"}],"children":[]},{"kind":"method","id":"blocklistremoveaddressaddress-type","name":"removeAddress","title":"`blockList.removeAddress(address[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"address","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"An IPv4 or IPv6 address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Removes a rule that was previously added with `blockList.addAddress()`. The\naddress must match exactly the value used when the rule was added. If the\nspecified address does not exist, this is a no-op.","summary":"Removes a rule that was previously added with `blockList.addAddress()`. The address must match exactly the value used when the rule was added. If the specified address does not exist, this is a no-op.","examples":[],"children":[]},{"kind":"method","id":"blocklistremovecidrcidr","name":"removeCIDR","title":"`blockList.removeCIDR(cidr)`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"cidr","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An IPv4 or IPv6 subnet in CIDR notation (e.g.\n`'10.0.0.0/8'` or `'2001:db8::/32'`).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Removes a subnet rule using CIDR notation. The address family is automatically\ndetected from the address. This is equivalent to calling\n`blockList.removeSubnet()` with the parsed network address, prefix length,\nand family. If the specified subnet does not exist, this is a no-op.","summary":"Removes a subnet rule using CIDR notation. The address family is automatically detected from the address. This is equivalent to calling `blockList.removeSubnet()` with the parsed network address, prefix length, and family. If the specified subnet does not exist, this is a no-op.","examples":[],"children":[]},{"kind":"method","id":"blocklistremoverangestart-end-type","name":"removeRange","title":"`blockList.removeRange(start, end[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"start","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The starting IPv4 or IPv6 address in the\nrange.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"end","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The ending IPv4 or IPv6 address in the range.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Removes a rule that was previously added with `blockList.addRange()`. The `start`\nand `end` addresses must match exactly the values used when the rule was added.\nIf the specified range does not exist, this is a no-op.","summary":"Removes a rule that was previously added with `blockList.addRange()`. The `start` and `end` addresses must match exactly the values used when the rule was added. If the specified range does not exist, this is a no-op.","examples":[],"children":[]},{"kind":"method","id":"blocklistremovesubnetnet-prefix-type","name":"removeSubnet","title":"`blockList.removeSubnet(net, prefix[, type])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"net","type":{"text":"string | net.SocketAddress","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":9,"end":26}]},"description":"The network IPv4 or IPv6 address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"prefix","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The number of CIDR prefix bits. For IPv4, this\nmust be a value between `0` and `32`. For IPv6, this must be between\n`0` and `128`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"type","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Either `'ipv4'` or `'ipv6'`.","default":"'ipv4'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Removes a rule that was previously added with `blockList.addSubnet()`. The\nnetwork address and prefix must match exactly the values used when the rule was\nadded. If the specified subnet does not exist, this is a no-op.","summary":"Removes a rule that was previously added with `blockList.addSubnet()`. The network address and prefix must match exactly the values used when the rule was added. If the specified subnet does not exist, this is a no-op.","examples":[],"children":[]},{"kind":"property","id":"blocklistrules","name":"rules","title":"`blockList.rules`","scope":"module","overloadOf":null,"stability":null,"added":["v15.0.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The list of rules added to the blocklist.","summary":"The list of rules added to the blocklist.","examples":[],"children":[]},{"kind":"property","id":"blocklistsize","name":"size","title":"`blockList.size`","scope":"module","overloadOf":null,"stability":null,"added":["v26.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of rules in the blocklist. This is equivalent to\n`blockList.rules.length` but does not allocate the rules array.","summary":"The number of rules in the blocklist. This is equivalent to `blockList.rules.length` but does not allocate the rules array.","examples":[],"children":[]},{"kind":"method","id":"blocklisttojson","name":"toJSON","title":"`blockList.toJSON()`","scope":"module","overloadOf":null,"stability":{"index":"1.2","description":"Release candidate"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":null,"description":"Blocklist.rules"}},"description":"<!-- YAML\nadded:\n - v24.5.0\n - v22.19.0\n-->","summary":"","examples":[],"children":[]}]},{"kind":"class","id":"class-netsocketaddress","name":"SocketAddress","title":"Class: `net.SocketAddress`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"","summary":"","examples":[],"children":[{"kind":"constructor","id":"new-netsocketaddressoptions","name":"SocketAddress","title":"`new net.SocketAddress([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"address","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The network address as either an IPv4 or IPv6 string.\n**Default**: `'127.0.0.1'` if `family` is `'ipv4'`; `'::'` if `family` is\n`'ipv6'`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"One of either `'ipv4'` or `'ipv6'`.\n**Default**: `'ipv4'`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"flowlabel","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"An IPv6 flow-label used only if `family` is `'ipv6'`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"An IP port.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"socketaddressaddress","name":"address","title":"`socketaddress.address`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"socketaddressfamily","name":"family","title":"`socketaddress.family`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Either `'ipv4'` or `'ipv6'`.","summary":"","examples":[],"children":[]},{"kind":"property","id":"socketaddressflowlabel","name":"flowlabel","title":"`socketaddress.flowlabel`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"socketaddressport","name":"port","title":"`socketaddress.port`","scope":"module","overloadOf":null,"stability":null,"added":["v15.14.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"socketaddressparseinput","name":"parse","title":"`SocketAddress.parse(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v23.4.0","v22.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"An input string containing an IP address and optional port,\ne.g. `123.1.2.3:1234` or `[1::1]:1234`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.SocketAddress","links":[{"name":"net.SocketAddress","href":"net.html#class-netsocketaddress","start":0,"end":17}]},"description":"Returns a `SocketAddress` if parsing was successful.\nOtherwise returns `undefined`."}},"description":"","summary":"","examples":[],"children":[]}]},{"kind":"class","id":"class-netserver","name":"Server","title":"Class: `net.Server`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":"This class is used to create a TCP or [IPC](#ipc-support) server.\n\nA listening TCP `net.Server` can be transferred to a worker thread by listing it\nin the `transferList` of a [`worker_threads`](worker_threads.html) `postMessage()` call. This moves\nthe underlying listening socket to the receiving thread, where it resumes\naccepting connections. See [Transferring TCP handles to other threads](#transferring-tcp-handles-to-other-threads).","summary":"This class is used to create a TCP or IPC server.","examples":[],"children":[{"kind":"constructor","id":"new-netserveroptions-connectionlistener","name":"Server","title":"`new net.Server([options][, connectionListener])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"See\n[`net.createServer([options][, connectionListener])`](#netcreateserveroptions-connectionlistener).","default":null,"optional":true,"rest":false,"properties":[]},{"name":"connectionListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Automatically set as a listener for the\n[`'connection'`](#event-connection) event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"`net.Server` is an [`EventEmitter`](events.html#class-eventemitter) with the following events:","summary":"`net.Server` is an `EventEmitter` with the following events:","examples":[],"children":[]},{"kind":"event","id":"event-close","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the server closes. If connections exist, this\nevent is not emitted until all connections are ended.","summary":"Emitted when the server closes. If connections exist, this event is not emitted until all connections are ended.","examples":[],"children":[]},{"kind":"event","id":"event-connection","name":"connection","title":"Event: `'connection'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"","type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The connection object","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when a new connection is made. `socket` is an instance of\n`net.Socket`.","summary":"Emitted when a new connection is made. `socket` is an instance of `net.Socket`.","examples":[],"children":[]},{"kind":"event","id":"event-error","name":"error","title":"Event: `'error'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when an error occurs. Unlike [`net.Socket`](#class-netsocket), the [`'close'`](#event-close)\nevent will **not** be emitted directly following this event unless\n[`server.close()`](#serverclosecallback) is manually called. See the example in discussion of\n[`server.listen()`](#serverlisten).","summary":"Emitted when an error occurs. Unlike `net.Socket`, the `'close'` event will **not** be emitted directly following this event unless `server.close()` is manually called. See the example in discussion of `server.listen()`.","examples":[],"children":[]},{"kind":"event","id":"event-listening","name":"listening","title":"Event: `'listening'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the server has been bound after calling [`server.listen()`](#serverlisten).","summary":"Emitted when the server has been bound after calling `server.listen()`.","examples":[],"children":[]},{"kind":"event","id":"event-drop","name":"drop","title":"Event: `'drop'`","scope":"module","overloadOf":null,"stability":null,"added":["v18.6.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"data","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"The argument passed to event listener.","default":null,"optional":false,"rest":false,"properties":[{"name":"localAddress","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Local address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"localPort","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Local port.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"localFamily","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Local family.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"remoteAddress","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Remote address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"remotePort","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Remote port.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"remoteFamily","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Remote IP family. `'IPv4'` or `'IPv6'`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"description":"When the number of connections reaches the threshold of `server.maxConnections`,\nthe server will drop new connections and emit `'drop'` event instead. If it is a\nTCP server, the argument is as follows, otherwise the argument is `undefined`.","summary":"When the number of connections reaches the threshold of `server.maxConnections`, the server will drop new connections and emit `'drop'` event instead. If it is a TCP server, the argument is as follows, otherwise the argument is `undefined`.","examples":[],"children":[]},{"kind":"method","id":"serveraddress","name":"address","title":"`server.address()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.4.0"],"prUrl":"https://github.com/nodejs/node/pull/43054","commit":null,"description":"The `family` property now returns a string instead of a number."},{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41431","commit":null,"description":"The `family` property now returns a number instead of a string."}],"signature":{"parameters":[],"returns":{"type":{"text":"Object | string | null","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":18,"end":22}]},"description":""}},"description":"Returns the bound `address`, the address `family` name, and `port` of the server\nas reported by the operating system if listening on an IP socket\n(useful to find which port was assigned when getting an OS-assigned address):\n`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.\n\nFor a server listening on a pipe or Unix domain socket, the name is returned\nas a string.\n\n```js\nconst server = net.createServer((socket) => {\n  socket.end('goodbye\\n');\n}).on('error', (err) => {\n  // Handle errors here.\n  throw err;\n});\n\n// Grab an arbitrary unused port.\nserver.listen(() => {\n  console.log('opened server on', server.address());\n});\n```\n\n`server.address()` returns `null` before the `'listening'` event has been\nemitted or after calling `server.close()`.","summary":"Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening on an IP socket (useful to find which port was assigned when getting an OS-assigned address): `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.","examples":[{"language":"js","displayName":null,"code":"const server = net.createServer((socket) => {\n  socket.end('goodbye\\n');\n}).on('error', (err) => {\n  // Handle errors here.\n  throw err;\n});\n\n// Grab an arbitrary unused port.\nserver.listen(() => {\n  console.log('opened server on', server.address());\n});"}],"children":[]},{"kind":"method","id":"serverclosecallback","name":"close","title":"`server.close([callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Called when the server is closed.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Stops the server from accepting new connections and keeps existing\nconnections. This function is asynchronous, the server is finally closed\nwhen all connections are ended and the server emits a [`'close'`](#event-close) event.\nThe optional `callback` will be called once the `'close'` event occurs. Unlike\nthat event, it will be called with an `Error` as its only argument if the server\nwas not open when it was closed.","summary":"Stops the server from accepting new connections and keeps existing connections. This function is asynchronous, the server is finally closed when all connections are ended and the server emits a `'close'` event. The optional `callback` will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its only argument if the server was not open when it was closed.","examples":[],"children":[]},{"kind":"method","id":"serversymbolasyncdispose","name":"[Symbol.asyncDispose]","title":"`server[Symbol.asyncDispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v20.5.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.2.0"],"prUrl":"https://github.com/nodejs/node/pull/58467","commit":null,"description":"No longer experimental."}],"signature":{"parameters":[],"returns":null},"description":"Calls [`server.close()`](#serverclosecallback) and returns a promise that fulfills when the\nserver has closed.","summary":"Calls `server.close()` and returns a promise that fulfills when the server has closed.","examples":[],"children":[]},{"kind":"method","id":"servergetconnectionscallback","name":"getConnections","title":"`server.getConnections(callback)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Asynchronously get the number of concurrent connections on the server. Works\nwhen sockets were sent to forks.\n\nCallback should take two arguments `err` and `count`.","summary":"Asynchronously get the number of concurrent connections on the server. Works when sockets were sent to forks.","examples":[],"children":[]},{"kind":"method","id":"serverlisten","name":"listen","title":"`server.listen()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Start a server listening for connections. A `net.Server` can be a TCP or\nan [IPC](#ipc-support) server depending on what it listens to.\n\nPossible signatures:\n\n* [`server.listen(handle[, backlog][, callback])`](#serverlistenhandle-backlog-callback)\n* [`server.listen(options[, callback])`](#serverlistenoptions-callback)\n* [`server.listen(path[, backlog][, callback])`](#serverlistenpath-backlog-callback)\n  for [IPC](#ipc-support) servers\n* [`server.listen([port[, host[, backlog]]][, callback])`](#serverlistenport-host-backlog-callback)\n  for TCP servers\n\nThis function is asynchronous. When the server starts listening, the\n[`'listening'`](#event-listening) event will be emitted. The last parameter `callback`\nwill be added as a listener for the [`'listening'`](#event-listening) event.\n\nAll `listen()` methods can take a `backlog` parameter to specify the maximum\nlength of the queue of pending connections. The actual length will be determined\nby the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn`\non Linux. The default value of this parameter is 511 (not 512).\n\nAll [`net.Socket`](#class-netsocket) are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for\ndetails).\n\nThe `server.listen()` method can be called again if and only if there was an\nerror during the first `server.listen()` call or `server.close()` has been\ncalled. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.\n\nOne of the most common errors raised when listening is `EADDRINUSE`.\nThis happens when another server is already listening on the requested\n`port`/`path`/`handle`. One way to handle this would be to retry\nafter a certain amount of time:\n\n```js\nserver.on('error', (e) => {\n  if (e.code === 'EADDRINUSE') {\n    console.error('Address in use, retrying...');\n    setTimeout(() => {\n      server.close();\n      server.listen(PORT, HOST);\n    }, 1000);\n  }\n});\n```","summary":"Start a server listening for connections. A `net.Server` can be a TCP or an IPC server depending on what it listens to.","examples":[{"language":"js","displayName":null,"code":"server.on('error', (e) => {\n  if (e.code === 'EADDRINUSE') {\n    console.error('Address in use, retrying...');\n    setTimeout(() => {\n      server.close();\n      server.listen(PORT, HOST);\n    }, 1000);\n  }\n});"}],"children":[{"kind":"method","id":"serverlistenhandle-backlog-callback","name":"listen","title":"`server.listen(handle[, backlog][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.10"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"handle","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"backlog","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Common parameter of [`server.listen()`](#serverlisten) functions","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Start a server listening for connections on a given `handle` that has\nalready been bound to a port, a Unix domain socket, or a Windows named pipe.\n\nThe `handle` object can be either a server, a socket (anything with an\nunderlying `_handle` member), a [`BoundSocket`](#class-netboundsocket), or an object with an `fd`\nmember that is a valid file descriptor.\n\nWhen `handle` is a [`BoundSocket`](#class-netboundsocket), the server adopts the already-bound\nsocket and starts listening on it. Adoption consumes the bound socket (see\n[ownership transfer](#class-netboundsocket)).\n\nListening on a file descriptor is not supported on Windows.","summary":"Start a server listening for connections on a given `handle` that has already been bound to a port, a Unix domain socket, or a Windows named pipe.","examples":[],"children":[]},{"kind":"method","id":"serverlistenoptions-callback","name":"listen","title":"`server.listen(options[, callback])`","scope":"module","overloadOf":"serverlistenhandle-backlog-callback","stability":null,"added":["v0.11.14"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v23.1.0","v22.12.0"],"prUrl":"https://github.com/nodejs/node/pull/55408","commit":null,"description":"The `reusePort` option is supported."},{"versions":["v15.6.0"],"prUrl":"https://github.com/nodejs/node/pull/36623","commit":null,"description":"AbortSignal support was added."},{"versions":["v11.4.0"],"prUrl":"https://github.com/nodejs/node/pull/23798","commit":null,"description":"The `ipv6Only` option is supported."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Required. Supports the following properties:","default":null,"optional":false,"rest":false,"properties":[{"name":"backlog","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Common parameter of [`server.listen()`](#serverlisten)\nfunctions.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"exclusive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"false","optional":true,"rest":false,"properties":[]},{"name":"handle","type":{"text":"net.BoundSocket","links":[{"name":"net.BoundSocket","href":"net.html#class-netboundsocket","start":0,"end":15}]},"description":"A pre-bound [`BoundSocket`](#class-netboundsocket). The server adopts\nthe already-bound socket and listens on it, ignoring `host`, `port`, and\n`path`. Adoption consumes the bound socket (see\n[ownership transfer](#class-netboundsocket)).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"ipv6Only","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"For TCP servers, setting `ipv6Only` to `true` will\ndisable dual-stack support, i.e., binding to host `::` won't make\n`0.0.0.0` be bound.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"reusePort","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"For TCP servers, setting `reusePort` to `true` allows\nmultiple sockets on the same host to bind to the same port. Incoming connections\nare distributed by the operating system to listening sockets. This option is\navailable only on some platforms, such as Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+,\nSolaris 11.4, and AIX 7.2.5+. On unsupported platforms, this option raises\nan error.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Will be ignored if `port` is specified. See\n[Identifying paths for IPC connections](#identifying-paths-for-ipc-connections).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"readableAll","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"For IPC servers makes the pipe readable\nfor all users.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An AbortSignal that may be used to close a listening\nserver.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"writableAll","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"For IPC servers makes the pipe writable\nfor all users.","default":"false","optional":true,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"functions.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"If `handle` is specified, the server adopts that pre-bound socket. Otherwise, if\n`port` is specified, it behaves the same as\n[`server.listen([port[, host[, backlog]]][, callback])`](#serverlistenport-host-backlog-callback).\nOtherwise, if `path` is specified, it behaves the same as\n[`server.listen(path[, backlog][, callback])`](#serverlistenpath-backlog-callback).\nIf none of them is specified, an error will be thrown.\n\nIf `exclusive` is `false` (default), then cluster workers will use the same\nunderlying handle, allowing connection handling duties to be shared. When\n`exclusive` is `true`, the handle is not shared, and attempted port sharing\nresults in an error. An example which listens on an exclusive port is\nshown below.\n\n```js\nserver.listen({\n  host: 'localhost',\n  port: 80,\n  exclusive: true,\n});\n```\n\nWhen `exclusive` is `true` and the underlying handle is shared, it is\npossible that several workers query a handle with different backlogs.\nIn this case, the first `backlog` passed to the master process will be used.\n\nStarting an IPC server as root may cause the server path to be inaccessible for\nunprivileged users. Using `readableAll` and `writableAll` will make the server\naccessible for all users.\n\nIf the `signal` option is enabled, calling `.abort()` on the corresponding\n`AbortController` is similar to calling `.close()` on the server:\n\n```js\nconst controller = new AbortController();\nserver.listen({\n  host: 'localhost',\n  port: 80,\n  signal: controller.signal,\n});\n// Later, when you want to close the server.\ncontroller.abort();\n```","summary":"If `handle` is specified, the server adopts that pre-bound socket. Otherwise, if `port` is specified, it behaves the same as `server.listen([port[, host[, backlog]]][, callback])`. Otherwise, if `path` is specified, it behaves the same as `server.listen(path[, backlog][, callback])`. If none of them is specified, an error will be thrown.","examples":[{"language":"js","displayName":null,"code":"server.listen({\n  host: 'localhost',\n  port: 80,\n  exclusive: true,\n});"},{"language":"js","displayName":null,"code":"const controller = new AbortController();\nserver.listen({\n  host: 'localhost',\n  port: 80,\n  signal: controller.signal,\n});\n// Later, when you want to close the server.\ncontroller.abort();"}],"children":[]},{"kind":"method","id":"serverlistenpath-backlog-callback","name":"listen","title":"`server.listen(path[, backlog][, callback])`","scope":"module","overloadOf":"serverlistenhandle-backlog-callback","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Path the server should listen to. See\n[Identifying paths for IPC connections](#identifying-paths-for-ipc-connections).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"backlog","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Common parameter of [`server.listen()`](#serverlisten) functions.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":".","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Start an [IPC](#ipc-support) server listening for connections on the given `path`.","summary":"Start an IPC server listening for connections on the given `path`.","examples":[],"children":[]},{"kind":"method","id":"serverlistenport-host-backlog-callback","name":"listen","title":"`server.listen([port[, host[, backlog]]][, callback])`","scope":"module","overloadOf":"serverlistenhandle-backlog-callback","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"backlog","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Common parameter of [`server.listen()`](#serverlisten) functions.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":".","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Start a TCP server listening for connections on the given `port` and `host`.\n\nIf `port` is omitted or is 0, the operating system will assign an arbitrary\nunused port, which can be retrieved by using `server.address().port`\nafter the [`'listening'`](#event-listening) event has been emitted.\n\nIf `host` is omitted, the server will accept connections on the\n[unspecified IPv6 address](https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address) (`::`) when IPv6 is available, or the\n[unspecified IPv4 address](https://en.wikipedia.org/wiki/0.0.0.0) (`0.0.0.0`) otherwise.\n\nIn most operating systems, listening to the [unspecified IPv6 address](https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address) (`::`)\nmay cause the `net.Server` to also listen on the [unspecified IPv4 address](https://en.wikipedia.org/wiki/0.0.0.0)\n(`0.0.0.0`).","summary":"Start a TCP server listening for connections on the given `port` and `host`.","examples":[],"children":[]}]},{"kind":"property","id":"serverlistening","name":"listening","title":"`server.listening`","scope":"module","overloadOf":null,"stability":null,"added":["v5.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Indicates whether or not the server is listening for connections.","summary":"","examples":[],"children":[]},{"kind":"property","id":"servermaxconnections","name":"maxConnections","title":"`server.maxConnections`","scope":"module","overloadOf":null,"stability":null,"added":["v0.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v21.0.0"],"prUrl":"https://github.com/nodejs/node/pull/48276","commit":null,"description":"Setting `maxConnections` to `0` drops all the incoming connections. Previously, it was interpreted as `Infinity`."}],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"When the number of connections reaches the `server.maxConnections` threshold:\n\n1. If the process is not running in cluster mode, Node.js will close the connection.\n\n2. If the process is running in cluster mode, Node.js will, by default, route the connection to another worker process. To close the connection instead, set [`server.dropMaxConnection`](#serverdropmaxconnection) to `true`.\n\nIt is not recommended to use this option once a socket has been sent to a child\nwith [`child_process.fork()`](child_process.html#child_processforkmodulepath-args-options).","summary":"When the number of connections reaches the `server.maxConnections` threshold:","examples":[],"children":[]},{"kind":"property","id":"serverdropmaxconnection","name":"dropMaxConnection","title":"`server.dropMaxConnection`","scope":"module","overloadOf":null,"stability":null,"added":["v23.1.0","v22.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Set this property to `true` to begin closing connections once the number of connections reaches the [`server.maxConnections`](#servermaxconnections) threshold. This setting is only effective in cluster mode.","summary":"Set this property to `true` to begin closing connections once the number of connections reaches the `server.maxConnections` threshold. This setting is only effective in cluster mode.","examples":[],"children":[]},{"kind":"method","id":"serverref","name":"ref","title":"`server.ref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will\n*not* let the program exit if it's the only server left (the default behavior).\nIf the server is `ref`ed calling `ref()` again will have no effect.","summary":"Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will _not_ let the program exit if it's the only server left (the default behavior). If the server is `ref`ed calling `ref()` again will have no effect.","examples":[],"children":[]},{"kind":"method","id":"serverunref","name":"unref","title":"`server.unref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Calling `unref()` on a server will allow the program to exit if this is the only\nactive server in the event system. If the server is already `unref`ed calling\n`unref()` again will have no effect.","summary":"Calling `unref()` on a server will allow the program to exit if this is the only active server in the event system. If the server is already `unref`ed calling `unref()` again will have no effect.","examples":[],"children":[]}]},{"kind":"class","id":"class-netsocket","name":"Socket","title":"Class: `net.Socket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"This class is an abstraction of a TCP socket or a streaming [IPC](#ipc-support) endpoint\n(uses named pipes on Windows, and Unix domain sockets otherwise). It is also\nan [`EventEmitter`](events.html#class-eventemitter).\n\nA `net.Socket` can be created by the user and used directly to interact with\na server. For example, it is returned by [`net.createConnection()`](#netcreateconnection),\nso the user can use it to talk to the server.\n\nIt can also be created by Node.js and passed to the user when a connection\nis received. For example, it is passed to the listeners of a\n[`'connection'`](#event-connection) event emitted on a [`net.Server`](#class-netserver), so the user can use\nit to interact with the client.","summary":"This class is an abstraction of a TCP socket or a streaming IPC endpoint (uses named pipes on Windows, and Unix domain sockets otherwise). It is also an `EventEmitter`.","examples":[],"children":[{"kind":"section","id":"transferring-tcp-handles-to-other-threads","name":"Transferring TCP handles to other threads","title":"Transferring TCP handles to other threads","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A connected TCP `net.Socket` can be moved to another thread by listing it in the\n`transferList` of a [`worker_threads`](worker_threads.html) `postMessage()` call. After the\ntransfer, the source socket is destroyed on the sending thread (further use\nfails with `ERR_STREAM_DESTROYED` rather than silently dropping data), and the\nsocket continues to work on the receiving thread. This makes it possible to\naccept connections on one thread and distribute them across a pool of worker\nthreads, for example to build a `node:cluster`-like model on top of worker\nthreads.\n\nThe socket must be a freshly accepted or created TCP connection: it must still\nbe attached to a live handle, must not be connecting or destroyed, and must not\nhave started reading or have buffered data. Otherwise `postMessage()` throws\n`ERR_WORKER_HANDLE_NOT_TRANSFERABLE`. Only TCP sockets are supported.\n\n```cjs\nconst net = require('node:net');\nconst { Worker } = require('node:worker_threads');\n\n// worker.js receives `{ socket }` messages and handles each connection.\nconst worker = new Worker('./worker.js');\n\nconst server = net.createServer((socket) => {\n  // Hand the freshly accepted connection off to the worker thread.\n  worker.postMessage({ socket }, [socket]);\n});\nserver.listen(8000);\n```\n\nA listening [`net.Server`](#class-netserver) can be transferred the same way, which moves the\nlistening socket itself (and its pending accept queue) to the receiving thread.","summary":"A connected TCP `net.Socket` can be moved to another thread by listing it in the `transferList` of a `worker_threads` `postMessage()` call. After the transfer, the source socket is destroyed on the sending thread (further use fails with `ERR_STREAM_DESTROYED` rather than silently dropping data), and the socket continues to work on the receiving thread. This makes it possible to accept connections on one thread and distribute them across a pool of worker threads, for example to build a `node:cluster`-like model on top of worker threads.","examples":[{"language":"cjs","displayName":null,"code":"const net = require('node:net');\nconst { Worker } = require('node:worker_threads');\n\n// worker.js receives `{ socket }` messages and handles each connection.\nconst worker = new Worker('./worker.js');\n\nconst server = net.createServer((socket) => {\n  // Hand the freshly accepted connection off to the worker thread.\n  worker.postMessage({ socket }, [socket]);\n});\nserver.listen(8000);"}],"children":[]},{"kind":"constructor","id":"new-netsocketoptions","name":"Socket","title":"`new net.Socket([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v25.6.0"],"prUrl":"https://github.com/nodejs/node/pull/61503","commit":null,"description":"Added `typeOfService` option."},{"versions":["v15.14.0"],"prUrl":"https://github.com/nodejs/node/pull/37735","commit":null,"description":"AbortSignal support was added."},{"versions":["v12.10.0"],"prUrl":"https://github.com/nodejs/node/pull/25436","commit":null,"description":"Added `onread` option."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Available options are:","default":null,"optional":true,"rest":false,"properties":[{"name":"allowHalfOpen","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `false`, then the socket will\nautomatically end the writable side when the readable side ends. See\n[`net.createServer()`](#netcreateserveroptions-connectionlistener) and the [`'end'`](#event-end) event for details.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"blockList","type":{"text":"net.BlockList","links":[{"name":"net.BlockList","href":"net.html#class-netblocklist","start":0,"end":13}]},"description":"`blockList` can be used for disabling outbound\naccess to specific IP addresses, IP ranges, or IP subnets.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"fd","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If specified, wrap around an existing socket with\nthe given file descriptor, otherwise a new socket will be created.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"handle","type":{"text":"net.BoundSocket","links":[{"name":"net.BoundSocket","href":"net.html#class-netboundsocket","start":0,"end":15}]},"description":"If specified, wrap around the bound socket from a\n[`BoundSocket`](#class-netboundsocket). A subsequent\n[`socket.connect()`](#socketconnect) uses the bound socket as the\nconnection's source binding (honoring the bound local address and port).\nAdoption consumes the bound socket (see\n[ownership transfer](#class-netboundsocket)).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"keepAlive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it enables keep-alive functionality on\nthe socket immediately after the connection is established, similarly on what\nis done in [`socket.setKeepAlive()`](#socketsetkeepalive).","default":"false","optional":true,"rest":false,"properties":[]},{"name":"keepAliveInitialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If set to a positive number, it sets the\ninitial delay before the first keepalive probe is sent on an idle socket.","default":"0","optional":true,"rest":false,"properties":[]},{"name":"noDelay","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it disables the use of Nagle's algorithm\nimmediately after the socket is established.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"onread","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"If specified, incoming data is stored in a single `buffer`\nand passed to the supplied `callback` when data arrives on the socket.\nThis will cause the streaming functionality to not provide any data.\nThe socket will emit events like `'error'`, `'end'`, and `'close'`\nas usual. Methods like `pause()` and `resume()` will also behave as\nexpected.","default":null,"optional":false,"rest":false,"properties":[{"name":"buffer","type":{"text":"Buffer | Uint8Array | Function","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":9,"end":19},{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":22,"end":30}]},"description":"Either a reusable chunk of memory to\nuse for storing incoming data or a function that returns such.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"This function is called for every chunk of incoming\ndata. Two arguments are passed to it: the number of bytes written to\n`buffer` and a reference to `buffer`. Return `false` from this function to\nimplicitly `pause()` the socket. This function will be executed in the\nglobal context.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"readable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Allow reads on the socket when an `fd` is passed,\notherwise ignored.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An Abort signal that may be used to destroy the\nsocket.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"typeOfService","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The initial Type of Service (TOS) value.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"writable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Allow writes on the socket when an `fd` is passed,\notherwise ignored.","default":"false","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Creates a new socket object.\n\nThe newly created socket can be either a TCP socket or a streaming [IPC](#ipc-support)\nendpoint, depending on what it [`connect()`](#socketconnect) to.","summary":"Creates a new socket object.","examples":[],"children":[]},{"kind":"event","id":"event-close-1","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"hadError","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the socket had a transmission error.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted once the socket is fully closed. The argument `hadError` is a boolean\nwhich says if the socket was closed due to a transmission error.","summary":"Emitted once the socket is fully closed. The argument `hadError` is a boolean which says if the socket was closed due to a transmission error.","examples":[],"children":[]},{"kind":"event","id":"event-connect","name":"connect","title":"Event: `'connect'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when a socket connection is successfully established.\nSee [`net.createConnection()`](#netcreateconnection).","summary":"Emitted when a socket connection is successfully established. See `net.createConnection()`.","examples":[],"children":[]},{"kind":"event","id":"event-connectionattempt","name":"connectionAttempt","title":"Event: `'connectionAttempt'`","scope":"module","overloadOf":null,"stability":null,"added":["v21.6.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"ip","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The IP which the socket is attempting to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The port which the socket is attempting to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The family of the IP. It can be `6` for IPv6 or `4` for IPv4.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when a new connection attempt is started. This may be emitted multiple times\nif the family autoselection algorithm is enabled in [`socket.connect(options)`](#socketconnectoptions-connectlistener).","summary":"Emitted when a new connection attempt is started. This may be emitted multiple times if the family autoselection algorithm is enabled in `socket.connect(options)`.","examples":[],"children":[]},{"kind":"event","id":"event-connectionattemptfailed","name":"connectionAttemptFailed","title":"Event: `'connectionAttemptFailed'`","scope":"module","overloadOf":null,"stability":null,"added":["v21.6.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"ip","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The IP which the socket attempted to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The port which the socket attempted to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The family of the IP. It can be `6` for IPv6 or `4` for IPv4.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"error","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"The error associated with the failure.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when a connection attempt failed. This may be emitted multiple times\nif the family autoselection algorithm is enabled in [`socket.connect(options)`](#socketconnectoptions-connectlistener).","summary":"Emitted when a connection attempt failed. This may be emitted multiple times if the family autoselection algorithm is enabled in `socket.connect(options)`.","examples":[],"children":[]},{"kind":"event","id":"event-connectionattempttimeout","name":"connectionAttemptTimeout","title":"Event: `'connectionAttemptTimeout'`","scope":"module","overloadOf":null,"stability":null,"added":["v21.6.0","v20.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"ip","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The IP which the socket attempted to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The port which the socket attempted to connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The family of the IP. It can be `6` for IPv6 or `4` for IPv4.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when a connection attempt timed out. This is only emitted (and may be\nemitted multiple times) if the family autoselection algorithm is enabled\nin [`socket.connect(options)`](#socketconnectoptions-connectlistener).","summary":"Emitted when a connection attempt timed out. This is only emitted (and may be emitted multiple times) if the family autoselection algorithm is enabled in `socket.connect(options)`.","examples":[],"children":[]},{"kind":"event","id":"event-data","name":"data","title":"Event: `'data'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"","type":{"text":"Buffer | string","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when data is received. The argument `data` will be a `Buffer` or\n`String`. Encoding of data is set by [`socket.setEncoding()`](#socketsetencodingencoding).\n\nThe data will be lost if there is no listener when a `Socket`\nemits a `'data'` event.","summary":"Emitted when data is received. The argument `data` will be a `Buffer` or `String`. Encoding of data is set by `socket.setEncoding()`.","examples":[],"children":[]},{"kind":"event","id":"event-drain","name":"drain","title":"Event: `'drain'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the write buffer becomes empty. Can be used to throttle uploads.\n\nSee also: the return values of `socket.write()`.","summary":"Emitted when the write buffer becomes empty. Can be used to throttle uploads.","examples":[],"children":[]},{"kind":"event","id":"event-end","name":"end","title":"Event: `'end'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the other end of the socket signals the end of transmission, thus\nending the readable side of the socket.\n\nBy default (`allowHalfOpen` is `false`) the socket will send an end of\ntransmission packet back and destroy its file descriptor once it has written out\nits pending write queue. However, if `allowHalfOpen` is set to `true`, the\nsocket will not automatically [`end()`](#socketenddata-encoding-callback) its writable side,\nallowing the user to write arbitrary amounts of data. The user must call\n[`end()`](#socketenddata-encoding-callback) explicitly to close the connection (i.e. sending a\nFIN packet back).","summary":"Emitted when the other end of the socket signals the end of transmission, thus ending the readable side of the socket.","examples":[],"children":[]},{"kind":"event","id":"event-error-1","name":"error","title":"Event: `'error'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when an error occurs. The `'close'` event will be called directly\nfollowing this event.","summary":"Emitted when an error occurs. The `'close'` event will be called directly following this event.","examples":[],"children":[]},{"kind":"event","id":"event-lookup","name":"lookup","title":"Event: `'lookup'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v5.10.0"],"prUrl":"https://github.com/nodejs/node/pull/5598","commit":null,"description":"The `host` parameter is supported now."}],"parameters":[{"name":"err","type":{"text":"Error | null","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":8,"end":12}]},"description":"The error object. See [`dns.lookup()`](dns.html#dnslookuphostname-options-callback).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"address","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The IP address.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"number | null","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":9,"end":13}]},"description":"The address type. See [`dns.lookup()`](dns.html#dnslookuphostname-options-callback).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The host name.","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted after resolving the host name but before connecting.\nNot applicable to Unix sockets.","summary":"Emitted after resolving the host name but before connecting. Not applicable to Unix sockets.","examples":[],"children":[]},{"kind":"event","id":"event-ready","name":"ready","title":"Event: `'ready'`","scope":"module","overloadOf":null,"stability":null,"added":["v9.11.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when a socket is ready to be used.\n\nTriggered immediately after `'connect'`.","summary":"Emitted when a socket is ready to be used.","examples":[],"children":[]},{"kind":"event","id":"event-timeout","name":"timeout","title":"Event: `'timeout'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted if the socket times out from inactivity. This is only to notify that\nthe socket has been idle. The user must manually close the connection.\n\nSee also: [`socket.setTimeout()`](#socketsettimeouttimeout-callback).","summary":"Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.","examples":[],"children":[]},{"kind":"method","id":"socketaddress","name":"address","title":"`socket.address()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.4.0"],"prUrl":"https://github.com/nodejs/node/pull/43054","commit":null,"description":"The `family` property now returns a string instead of a number."},{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41431","commit":null,"description":"The `family` property now returns a number instead of a string."}],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns the bound `address`, the address `family` name and `port` of the\nsocket as reported by the operating system:\n`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`","summary":"Returns the bound `address`, the address `family` name and `port` of the socket as reported by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`","examples":[],"children":[]},{"kind":"property","id":"socketautoselectfamilyattemptedaddresses","name":"autoSelectFamilyAttemptedAddresses","title":"`socket.autoSelectFamilyAttemptedAddresses`","scope":"module","overloadOf":null,"stability":null,"added":["v19.4.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"This property is only present if the family autoselection algorithm is enabled in\n[`socket.connect(options)`](#socketconnectoptions-connectlistener) and it is an array of the addresses that have been attempted.\n\nEach address is a string in the form of `$IP:$PORT`. If the connection was successful,\nthen the last address is the one that the socket is currently connected to.","summary":"This property is only present if the family autoselection algorithm is enabled in `socket.connect(options)` and it is an array of the addresses that have been attempted.","examples":[],"children":[]},{"kind":"property","id":"socketbuffersize","name":"bufferSize","title":"`socket.bufferSize`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated: Use [`writable.writableLength`](stream.html#writablewritablelength) instead."},"added":["v0.3.8"],"deprecated":["v14.6.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"This property shows the number of characters buffered for writing. The buffer\nmay contain strings whose length after encoding is not yet known. So this number\nis only an approximation of the number of bytes in the buffer.\n\n`net.Socket` has the property that `socket.write()` always works. This is to\nhelp users get up and running quickly. The computer cannot always keep up\nwith the amount of data that is written to a socket. The network connection\nsimply might be too slow. Node.js will internally queue up the data written to a\nsocket and send it out over the wire when it is possible.\n\nThe consequence of this internal buffering is that memory may grow.\nUsers who experience large or growing `bufferSize` should attempt to\n\"throttle\" the data flows in their program with\n[`socket.pause()`](#socketpause) and [`socket.resume()`](#socketresume).","summary":"This property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer.","examples":[],"children":[]},{"kind":"property","id":"socketbytesread","name":"bytesRead","title":"`socket.bytesRead`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"The amount of received bytes.","summary":"The amount of received bytes.","examples":[],"children":[]},{"kind":"property","id":"socketbyteswritten","name":"bytesWritten","title":"`socket.bytesWritten`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"The amount of bytes sent.","summary":"The amount of bytes sent.","examples":[],"children":[]},{"kind":"method","id":"socketconnect","name":"connect","title":"`socket.connect()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Initiate a connection on a given socket.\n\nPossible signatures:\n\n* [`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener)\n* [`socket.connect(path[, connectListener])`](#socketconnectpath-connectlistener)\n  for [IPC](#ipc-support) connections.\n* [`socket.connect(port[, host][, connectListener])`](#socketconnectport-host-connectlistener)\n  for TCP connections.\n* Returns: {net.Socket} The socket itself.\n\nThis function is asynchronous. When the connection is established, the\n[`'connect'`](#event-connect) event will be emitted. If there is a problem connecting,\ninstead of a [`'connect'`](#event-connect) event, an [`'error'`](#event-error_1) event will be emitted with\nthe error passed to the [`'error'`](#event-error_1) listener.\nThe last parameter `connectListener`, if supplied, will be added as a listener\nfor the [`'connect'`](#event-connect) event **once**.\n\nThis function should only be used for reconnecting a socket after\n`'close'` has been emitted or otherwise it may lead to undefined\nbehavior.","summary":"Initiate a connection on a given socket.","examples":[],"children":[{"kind":"method","id":"socketconnectoptions-connectlistener","name":"connect","title":"`socket.connect(options[, connectListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.0.0","v18.18.0"],"prUrl":"https://github.com/nodejs/node/pull/46790","commit":null,"description":"The default value for the autoSelectFamily option is now true. The `--enable-network-family-autoselection` CLI flag has been renamed to `--network-family-autoselection`. The old name is now an alias but it is discouraged."},{"versions":["v19.4.0"],"prUrl":"https://github.com/nodejs/node/pull/45777","commit":null,"description":"The default value for autoSelectFamily option can be changed at runtime using `setDefaultAutoSelectFamily` or via the command line option `--enable-network-family-autoselection`."},{"versions":["v19.3.0","v18.13.0"],"prUrl":"https://github.com/nodejs/node/pull/44731","commit":null,"description":"Added the `autoSelectFamily` option."},{"versions":["v17.7.0","v16.15.0"],"prUrl":"https://github.com/nodejs/node/pull/41310","commit":null,"description":"The `noDelay`, `keepAlive`, and `keepAliveInitialDelay` options are supported now."},{"versions":["v6.0.0"],"prUrl":"https://github.com/nodejs/node/pull/6021","commit":null,"description":"The `hints` option defaults to `0` in all cases now. Previously, in the absence of the `family` option it would default to `dns.ADDRCONFIG | dns.V4MAPPED`."},{"versions":["v5.11.0"],"prUrl":"https://github.com/nodejs/node/pull/6000","commit":null,"description":"The `hints` option is supported now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of [`socket.connect()`](#socketconnect)\nmethods. Will be added as a listener for the [`'connect'`](#event-connect) event once.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Initiate a connection on a given socket. Normally this method is not needed,\nthe socket should be created and opened with [`net.createConnection()`](#netcreateconnection). Use\nthis only when implementing a custom Socket.\n\nFor TCP connections, available `options` are:\n\n* `autoSelectFamily` {boolean}: If set to `true`, it enables a family\n  autodetection algorithm that loosely implements section 5 of [RFC 8305](https://www.rfc-editor.org/rfc/rfc8305.txt). The\n  `all` option passed to lookup is set to `true` and the sockets attempts to\n  connect to all obtained IPv6 and IPv4 addresses, in sequence, until a\n  connection is established. The first returned AAAA address is tried first,\n  then the first returned A address, then the second returned AAAA address and\n  so on. Each connection attempt (but the last one) is given the amount of time\n  specified by the `autoSelectFamilyAttemptTimeout` option before timing out and\n  trying the next address. Ignored if the `family` option is not `0` or if\n  `localAddress` is set. Connection errors are not emitted if at least one\n  connection succeeds. If all connections attempts fails, a single\n  `AggregateError` with all failed attempts is emitted. **Default:**\n  [`net.getDefaultAutoSelectFamily()`](#netgetdefaultautoselectfamily).\n* `autoSelectFamilyAttemptTimeout` {number}: The amount of time in milliseconds\n  to wait for a connection attempt to finish before trying the next address when\n  using the `autoSelectFamily` option. If set to a positive integer less than\n  `10`, then the value `10` will be used instead. **Default:**\n  [`net.getDefaultAutoSelectFamilyAttemptTimeout()`](#netgetdefaultautoselectfamilyattempttimeout).\n* `family` {number}: Version of IP stack. Must be `4`, `6`, or `0`. The value\n  `0` indicates that both IPv4 and IPv6 addresses are allowed. **Default:** `0`.\n* `hints` {number} Optional [`dns.lookup()` hints](dns.html#supported-getaddrinfo-flags).\n* `host` {string} Host the socket should connect to. **Default:** `'localhost'`.\n* `localAddress` {string} Local address the socket should connect from.\n* `localPort` {number} Local port the socket should connect from.\n* `lookup` {Function} Custom lookup function. **Default:** [`dns.lookup()`](dns.html#dnslookuphostname-options-callback).\n* `port` {number} Required. Port the socket should connect to.\n\nFor [IPC](#ipc-support) connections, available `options` are:\n\n* `path` {string} Required. Path the client should connect to.\n  See [Identifying paths for IPC connections](#identifying-paths-for-ipc-connections). If provided, the TCP-specific\n  options above are ignored.","summary":"Initiate a connection on a given socket. Normally this method is not needed, the socket should be created and opened with `net.createConnection()`. Use this only when implementing a custom Socket.","examples":[],"children":[]},{"kind":"method","id":"socketconnectpath-connectlistener","name":"connect","title":"`socket.connect(path[, connectListener])`","scope":"module","overloadOf":"socketconnectoptions-connectlistener","stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Path the client should connect to. See\n[Identifying paths for IPC connections](#identifying-paths-for-ipc-connections).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of [`socket.connect()`](#socketconnect)\nmethods. Will be added as a listener for the [`'connect'`](#event-connect) event once.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Initiate an [IPC](#ipc-support) connection on the given socket.\n\nAlias to\n[`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener)\ncalled with `{ path: path }` as `options`.","summary":"Initiate an IPC connection on the given socket.","examples":[],"children":[]},{"kind":"method","id":"socketconnectport-host-connectlistener","name":"connect","title":"`socket.connect(port[, host][, connectListener])`","scope":"module","overloadOf":"socketconnectoptions-connectlistener","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Port the client should connect to.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Host the client should connect to.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of [`socket.connect()`](#socketconnect)\nmethods. Will be added as a listener for the [`'connect'`](#event-connect) event once.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Initiate a TCP connection on the given socket.\n\nAlias to\n[`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener)\ncalled with `{port: port, host: host}` as `options`.","summary":"Initiate a TCP connection on the given socket.","examples":[],"children":[]}]},{"kind":"property","id":"socketconnecting","name":"connecting","title":"`socket.connecting`","scope":"module","overloadOf":null,"stability":null,"added":["v6.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"If `true`,\n[`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener) was\ncalled and has not yet finished. It will stay `true` until the socket becomes\nconnected, then it is set to `false` and the `'connect'` event is emitted. Note\nthat the\n[`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener)\ncallback is a listener for the `'connect'` event.","summary":"If `true`, `socket.connect(options[, connectListener])` was called and has not yet finished. It will stay `true` until the socket becomes connected, then it is set to `false` and the `'connect'` event is emitted. Note that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.","examples":[],"children":[]},{"kind":"method","id":"socketdestroyerror","name":"destroy","title":"`socket.destroy([error])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"error","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Ensures that no more I/O activity happens on the current connection.\nDestroys the stream and closes the connection.\n\nSee [`writable.destroy()`](stream.html#writabledestroyerror) for further details.","summary":"Ensures that no more I/O activity happens on the current connection. Destroys the stream and closes the connection.","examples":[],"children":[]},{"kind":"property","id":"socketdestroyed","name":"destroyed","title":"`socket.destroyed`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Indicates if the connection is destroyed or not. No further\ndata can be transferred using a destroyed connection.\n\nSee [`writable.destroyed`](stream.html#writabledestroyed) for further details.","summary":"See `writable.destroyed` for further details.","examples":[],"children":[]},{"kind":"method","id":"socketdestroysoon","name":"destroySoon","title":"`socket.destroySoon()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Destroys the socket after all data is written. If the `'finish'` event was\nalready emitted the socket is destroyed immediately. If the socket is still\nwritable it implicitly calls `socket.end()`.","summary":"Destroys the socket after all data is written. If the `'finish'` event was already emitted the socket is destroyed immediately. If the socket is still writable it implicitly calls `socket.end()`.","examples":[],"children":[]},{"kind":"method","id":"socketenddata-encoding-callback","name":"end","title":"`socket.end([data[, encoding]][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"data","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Only used when data is `string`.","default":"'utf8'","optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Optional callback for when the socket is finished.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Half-closes the socket. i.e., it sends a FIN packet. It is possible the\nserver will still send some data.\n\nSee [`writable.end()`](stream.html#writableendchunk-encoding-callback) for further details.","summary":"Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.","examples":[],"children":[]},{"kind":"property","id":"socketlocaladdress","name":"localAddress","title":"`socket.localAddress`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The string representation of the local IP address the remote client is\nconnecting on. For example, in a server listening on `'0.0.0.0'`, if a client\nconnects on `'192.168.1.1'`, the value of `socket.localAddress` would be\n`'192.168.1.1'`.","summary":"The string representation of the local IP address the remote client is connecting on. For example, in a server listening on `'0.0.0.0'`, if a client connects on `'192.168.1.1'`, the value of `socket.localAddress` would be `'192.168.1.1'`.","examples":[],"children":[]},{"kind":"property","id":"socketlocalport","name":"localPort","title":"`socket.localPort`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"The numeric representation of the local port. For example, `80` or `21`.","summary":"The numeric representation of the local port. For example, `80` or `21`.","examples":[],"children":[]},{"kind":"property","id":"socketlocalfamily","name":"localFamily","title":"`socket.localFamily`","scope":"module","overloadOf":null,"stability":null,"added":["v18.8.0","v16.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The string representation of the local IP family. `'IPv4'` or `'IPv6'`.","summary":"The string representation of the local IP family. `'IPv4'` or `'IPv6'`.","examples":[],"children":[]},{"kind":"method","id":"socketpause","name":"pause","title":"`socket.pause()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Pauses the reading of data. That is, [`'data'`](#event-data) events will not be emitted.\nUseful to throttle back an upload.","summary":"Pauses the reading of data. That is, `'data'` events will not be emitted. Useful to throttle back an upload.","examples":[],"children":[]},{"kind":"property","id":"socketpending","name":"pending","title":"`socket.pending`","scope":"module","overloadOf":null,"stability":null,"added":["v11.2.0","v10.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"This is `true` if the socket is not connected yet, either because `.connect()`\nhas not yet been called or because it is still in the process of connecting\n(see [`socket.connecting`](#socketconnecting)).","summary":"This is `true` if the socket is not connected yet, either because `.connect()` has not yet been called or because it is still in the process of connecting (see `socket.connecting`).","examples":[],"children":[]},{"kind":"method","id":"socketref","name":"ref","title":"`socket.ref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will\n*not* let the program exit if it's the only socket left (the default behavior).\nIf the socket is `ref`ed calling `ref` again will have no effect.","summary":"Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will _not_ let the program exit if it's the only socket left (the default behavior). If the socket is `ref`ed calling `ref` again will have no effect.","examples":[],"children":[]},{"kind":"property","id":"socketremoteaddress","name":"remoteAddress","title":"`socket.remoteAddress`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.10"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The string representation of the remote IP address. For example,\n`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if\nthe socket is destroyed (for example, if the client disconnected).","summary":"The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected).","examples":[],"children":[]},{"kind":"property","id":"socketremotefamily","name":"remoteFamily","title":"`socket.remoteFamily`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.14"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if\nthe socket is destroyed (for example, if the client disconnected).","summary":"The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected).","examples":[],"children":[]},{"kind":"property","id":"socketremoteport","name":"remotePort","title":"`socket.remotePort`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.10"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"default":null,"description":"The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if\nthe socket is destroyed (for example, if the client disconnected).","summary":"The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected).","examples":[],"children":[]},{"kind":"property","id":"socketserver","name":"server","title":"`socket.server`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"net.Server | null","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":13,"end":17}]},"default":null,"description":"Reference to the server that accepted the socket. This is `null` for sockets\nthat were not accepted by a server.","summary":"Reference to the server that accepted the socket. This is `null` for sockets that were not accepted by a server.","examples":[],"children":[]},{"kind":"method","id":"socketresetanddestroy","name":"resetAndDestroy","title":"`socket.resetAndDestroy()`","scope":"module","overloadOf":null,"stability":null,"added":["v18.3.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Close the TCP connection by sending an RST packet and destroy the stream.\nIf this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.\nOtherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error.\nIf this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.","summary":"Close the TCP connection by sending an RST packet and destroy the stream. If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected. Otherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error. If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.","examples":[],"children":[]},{"kind":"method","id":"socketresume","name":"resume","title":"`socket.resume()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Resumes reading after a call to [`socket.pause()`](#socketpause).","summary":"Resumes reading after a call to `socket.pause()`.","examples":[],"children":[]},{"kind":"method","id":"socketsetencodingencoding","name":"setEncoding","title":"`socket.setEncoding([encoding])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Set the encoding for the socket as a [Readable Stream](stream.html#class-streamreadable). See\n[`readable.setEncoding()`](stream.html#readablesetencodingencoding) for more information.","summary":"Set the encoding for the socket as a Readable Stream. See `readable.setEncoding()` for more information.","examples":[],"children":[]},{"kind":"method","id":"socketsetkeepalive","name":"setKeepAlive","title":"`socket.setKeepAlive()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Enable/disable keep-alive functionality, and optionally configure the\nkeepalive probe timing. Returns the socket itself.\n\nPossible signatures:\n\n* [`socket.setKeepAlive([options])`](#socketsetkeepaliveoptions)\n* [`socket.setKeepAlive([enable][, initialDelay][, interval][, count])`](#socketsetkeepaliveenable-initialdelay-interval-count)\n\nEnabling keep-alive sets the initial delay before the first keepalive probe is\nsent on an idle socket.\n\nSet `initialDelay` (in milliseconds) to set the delay between the last\ndata packet received and the first keepalive probe. Setting `0` for\n`initialDelay` will leave the value unchanged from the default\n(or previous) setting.\n\nSet `interval` (in milliseconds) to set the delay between successive\nkeepalive probes once they begin (`TCP_KEEPINTVL`). Set `count` to the\nnumber of unacknowledged probes sent before the connection is dropped\n(`TCP_KEEPCNT`). Both are only applied when keep-alive is enabled.\nOmitting `interval` or `count` uses the defaults of `1000` ms and `10`.\nAs with `initialDelay`, a non-positive `interval` or `count` leaves the\ncorresponding system default unchanged.\n\n`initialDelay` and `interval` are specified in milliseconds but the\nunderlying socket options are configured in whole seconds; the values are\ndivided by `1000` and rounded down before being applied.\n\nEnabling the keep-alive functionality will set the following socket options:\n\n* `SO_KEEPALIVE=1`\n* `TCP_KEEPIDLE=initialDelay / 1000`\n* `TCP_KEEPCNT=count`\n* `TCP_KEEPINTVL=interval / 1000`\n\nOn Windows versions older than build 1709, keep-alive is configured through\n`SIO_KEEPALIVE_VALS`, which has no probe-count field, so `count` is ignored on\nthose platforms.","summary":"Enable/disable keep-alive functionality, and optionally configure the keepalive probe timing. Returns the socket itself.","examples":[],"children":[{"kind":"method","id":"socketsetkeepaliveoptions","name":"setKeepAlive","title":"`socket.setKeepAlive([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"enable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"false","optional":true,"rest":false,"properties":[]},{"name":"initialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"0","optional":true,"rest":false,"properties":[]},{"name":"interval","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"1000","optional":true,"rest":false,"properties":[]},{"name":"count","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"10","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Configure keep-alive using an options object. See [`socket.setKeepAlive()`](#socketsetkeepalive)\nfor a description of each property.\n\n```js\nsocket.setKeepAlive({ enable: true, initialDelay: 1000, interval: 1000, count: 10 });\n```","summary":"Configure keep-alive using an options object. See `socket.setKeepAlive()` for a description of each property.","examples":[{"language":"js","displayName":null,"code":"socket.setKeepAlive({ enable: true, initialDelay: 1000, interval: 1000, count: 10 });"}],"children":[]},{"kind":"method","id":"socketsetkeepaliveenable-initialdelay-interval-count","name":"setKeepAlive","title":"`socket.setKeepAlive([enable][, initialDelay][, interval][, count])`","scope":"module","overloadOf":"socketsetkeepaliveoptions","stability":null,"added":["v0.1.92"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.4.0"],"prUrl":"https://github.com/nodejs/node/pull/63825","commit":null,"description":"Added the `interval` and `count` arguments to configure `TCP_KEEPINTVL` and `TCP_KEEPCNT`."},{"versions":["v13.12.0","v12.17.0"],"prUrl":"https://github.com/nodejs/node/pull/32204","commit":null,"description":"New defaults for `TCP_KEEPCNT` and `TCP_KEEPINTVL` socket options were added."}],"signature":{"parameters":[{"name":"enable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"false","optional":true,"rest":false,"properties":[]},{"name":"initialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"0","optional":true,"rest":false,"properties":[]},{"name":"interval","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"1000","optional":true,"rest":false,"properties":[]},{"name":"count","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"10","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Configure keep-alive using positional arguments. See\n[`socket.setKeepAlive()`](#socketsetkeepalive) for a description of each argument.","summary":"Configure keep-alive using positional arguments. See `socket.setKeepAlive()` for a description of each argument.","examples":[],"children":[]}]},{"kind":"method","id":"socketsetnodelaynodelay","name":"setNoDelay","title":"`socket.setNoDelay([noDelay])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"noDelay","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"true","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Enable/disable the use of Nagle's algorithm.\n\nWhen a TCP connection is created, it will have Nagle's algorithm enabled.\n\nNagle's algorithm delays data before it is sent via the network. It attempts\nto optimize throughput at the expense of latency.\n\nPassing `true` for `noDelay` or not passing an argument will disable Nagle's\nalgorithm for the socket. Passing `false` for `noDelay` will enable Nagle's\nalgorithm.","summary":"Enable/disable the use of Nagle's algorithm.","examples":[],"children":[]},{"kind":"method","id":"socketsettimeouttimeout-callback","name":"setTimeout","title":"`socket.setTimeout(timeout[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"timeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Sets the socket to timeout after `timeout` milliseconds of inactivity on\nthe socket. By default `net.Socket` do not have a timeout.\n\nWhen an idle timeout is triggered the socket will receive a [`'timeout'`](#event-timeout)\nevent but the connection will not be severed. The user must manually call\n[`socket.end()`](#socketenddata-encoding-callback) or [`socket.destroy()`](#socketdestroyerror) to end the connection.\n\n```js\nsocket.setTimeout(3000);\nsocket.on('timeout', () => {\n  console.log('socket timeout');\n  socket.end();\n});\n```\n\nIf `timeout` is 0, then the existing idle timeout is disabled.\n\nThe optional `callback` parameter will be added as a one-time listener for the\n[`'timeout'`](#event-timeout) event.","summary":"Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `net.Socket` do not have a timeout.","examples":[{"language":"js","displayName":null,"code":"socket.setTimeout(3000);\nsocket.on('timeout', () => {\n  console.log('socket timeout');\n  socket.end();\n});"}],"children":[]},{"kind":"method","id":"socketgettypeofservice","name":"getTypeOfService","title":"`socket.getTypeOfService()`","scope":"module","overloadOf":null,"stability":null,"added":["v25.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"The current TOS value."}},"description":"Returns the current Type of Service (TOS) field for IPv4 packets or Traffic\nClass for IPv6 packets for this socket.\n\n`setTypeOfService()` may be called before the socket is connected; the value\nwill be cached and applied when the socket establishes a connection.\n`getTypeOfService()` will return the currently set value even before connection.\n\nOn some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,\nand behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers\nshould verify platform-specific semantics.","summary":"Returns the current Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6 packets for this socket.","examples":[],"children":[]},{"kind":"method","id":"socketsettypeofservicetos","name":"setTypeOfService","title":"`socket.setTypeOfService(tos)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"tos","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"The TOS value to set (0-255).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6\nPackets sent from this socket. This can be used to prioritize network traffic.\n\n`setTypeOfService()` may be called before the socket is connected; the value\nwill be cached and applied when the socket establishes a connection.\n`getTypeOfService()` will return the currently set value even before connection.\n\nOn some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,\nand behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers\nshould verify platform-specific semantics.","summary":"Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6 Packets sent from this socket. This can be used to prioritize network traffic.","examples":[],"children":[]},{"kind":"property","id":"sockettimeout","name":"timeout","title":"`socket.timeout`","scope":"module","overloadOf":null,"stability":null,"added":["v10.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number | undefined","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"default":null,"description":"The socket timeout in milliseconds as set by [`socket.setTimeout()`](#socketsettimeouttimeout-callback).\nIt is `undefined` if a timeout has not been set.","summary":"The socket timeout in milliseconds as set by `socket.setTimeout()`. It is `undefined` if a timeout has not been set.","examples":[],"children":[]},{"kind":"method","id":"socketunref","name":"unref","title":"`socket.unref()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The socket itself."}},"description":"Calling `unref()` on a socket will allow the program to exit if this is the only\nactive socket in the event system. If the socket is already `unref`ed calling\n`unref()` again will have no effect.","summary":"Calling `unref()` on a socket will allow the program to exit if this is the only active socket in the event system. If the socket is already `unref`ed calling `unref()` again will have no effect.","examples":[],"children":[]},{"kind":"method","id":"socketwritedata-encoding-callback","name":"write","title":"`socket.write(data[, encoding][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"data","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Only used when data is `string`.","default":"utf8","optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Sends data on the socket. The second parameter specifies the encoding in the\ncase of a string. It defaults to UTF8 encoding.\n\nReturns `true` if the entire data was flushed successfully to the kernel\nbuffer. Returns `false` if all or part of the data was queued in user memory.\n[`'drain'`](#event-drain) will be emitted when the buffer is again free.\n\nThe optional `callback` parameter will be executed when the data is finally\nwritten out, which may not be immediately.\n\nSee `Writable` stream [`write()`](stream.html#writablewritechunk-encoding-callback) method for more\ninformation.","summary":"Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.","examples":[],"children":[]},{"kind":"property","id":"socketreadystate","name":"readyState","title":"`socket.readyState`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"This property represents the state of the connection as a string.\n\n* If the socket is connecting, `socket.readyState` is `opening`.\n* If the socket is readable and writable, it is `open`.\n* If the socket is readable and not writable, it is `readOnly`.\n* If the socket is not readable and writable, it is `writeOnly`.\n* Otherwise, it is `closed`.","summary":"This property represents the state of the connection as a string.","examples":[],"children":[]}]},{"kind":"class","id":"class-netboundsocket","name":"BoundSocket","title":"Class: `net.BoundSocket`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"Allows for the synchronous creation of a pre-bound socket, that can be passed\nto `listen()` or `new net.Socket()` later on. For `listen()` this enables\nsynchronous port reservation, while for `new net.Socket()`, it allows control\nover the local egress port/IP, via `bind(2)` semantics.\n\nA `BoundSocket` binds either a TCP endpoint (`host` or `port`) or a\nUnix domain/named-pipe endpoint (`path`); the two are mutually exclusive. For a\n`path`, the file system entry is reserved in the constructor, so conflicts such\nas `EADDRINUSE` throw synchronously exactly as a TCP bind does. On Linux a\nleading `'\\0'` in `path` selects the abstract namespace (no file system entry);\nan abstract path on any other platform throws [`ERR_INVALID_ARG_VALUE`](errors.html#err_invalid_arg_value).\n\nAdoption transfers ownership of the socket; afterwards `address()` and `close()`\nthrow [`ERR_SOCKET_HANDLE_ADOPTED`](errors.html#err_socket_handle_adopted). A handle that is never adopted must be\nclosed to avoid leaking the socket. Closing a pipe `BoundSocket` removes its\nfile system entry; abstract and TCP binds have none to remove.\n\nWhen a pipe `BoundSocket` bound to a source `path` is adopted as a client, that\npath is reported as the socket's `localAddress` once it connects.\n\nWhen an adopted `BoundSocket` connects to a numeric IP literal, `connect(2)` is\nissued synchronously, so [`socket.localAddress`](#socketlocaladdress) is resolved once\n[`socket.connect()`](#socketconnect) returns. Connection failures are still reported via a\ndeferred `'error'` event.\n\n```mjs\nimport net from 'node:net';\n\nconst bound = new net.BoundSocket();\nconst { port } = bound.address();\nconsole.log(`Reserved port ${port} for server`);\n\nconst server = net.createServer();\nserver.listen(bound); // Adopt as a server, or pass to new net.Socket() instead.\n```","summary":"Allows for the synchronous creation of a pre-bound socket, that can be passed to `listen()` or `new net.Socket()` later on. For `listen()` this enables synchronous port reservation, while for `new net.Socket()`, it allows control over the local egress port/IP, via `bind(2)` semantics.","examples":[{"language":"mjs","displayName":null,"code":"import net from 'node:net';\n\nconst bound = new net.BoundSocket();\nconst { port } = bound.address();\nconsole.log(`Reserved port ${port} for server`);\n\nconst server = net.createServer();\nserver.listen(bound); // Adopt as a server, or pass to new net.Socket() instead."}],"children":[{"kind":"constructor","id":"new-netboundsocketoptions","name":"BoundSocket","title":"`new net.BoundSocket([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.7.0"],"prUrl":"https://github.com/nodejs/node/pull/64399","commit":null,"description":"The `path` option is supported."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Local address to bind. Must be a numeric IP literal; no DNS\nresolution is performed.","default":"'0.0.0.0'`, or `'::'` when `ipv6Only` is `true","optional":true,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Local port. `0` requests an OS-assigned ephemeral port.","default":"0","optional":true,"rest":false,"properties":[]},{"name":"ipv6Only","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Sets `IPV6_V6ONLY`, disabling dual-stack support so the\nsocket binds IPv6 only. Only meaningful for IPv6 binds.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"reusePort","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Sets `SO_REUSEPORT`, allowing multiple sockets to bind\nthe same address and port for kernel-level load balancing. Support is\nplatform-dependent.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Binds a Unix domain socket (or Windows named pipe) at the\ngiven path instead of a TCP endpoint. A leading `'\\0'` selects the Linux\nabstract namespace. Mutually exclusive with `host`, `port`, `ipv6Only`, and\n`reusePort`; combining them throws [`ERR_INVALID_ARG_VALUE`](errors.html#err_invalid_arg_value).","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"boundsocketaddress","name":"address","title":"`boundSocket.address()`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.7.0"],"prUrl":"https://github.com/nodejs/node/pull/64399","commit":null,"description":"The bound path is returned for a pipe bind."}],"signature":{"parameters":[],"returns":{"type":{"text":"Object | string","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15}]},"description":"For a TCP bind, an object with `address`, `family`,\nand `port` properties, as [`server.address()`](#serveraddress) returns. For a pipe bind, the\nbound path string, as [`server.address()`](#serveraddress) returns for a pipe server."}},"description":"Returns the bound local address. When bound with `port: 0`, `port` is the\nOS-assigned ephemeral port.","summary":"Returns the bound local address. When bound with `port: 0`, `port` is the OS-assigned ephemeral port.","examples":[],"children":[]},{"kind":"property","id":"boundsocketispipe","name":"isPipe","title":"`boundSocket.isPipe`","scope":"module","overloadOf":null,"stability":null,"added":["v26.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"`true` when the socket was bound with a `path` (a Unix domain socket or Windows\nnamed pipe), `false` for a TCP bind. The getter's presence on\n`net.BoundSocket.prototype` also serves as a capability probe for `path`\nsupport.","summary":"`true` when the socket was bound with a `path` (a Unix domain socket or Windows named pipe), `false` for a TCP bind. The getter's presence on `net.BoundSocket.prototype` also serves as a capability probe for `path` support.","examples":[],"children":[]},{"kind":"method","id":"boundsocketfd","name":"fd","title":"`boundSocket.fd()`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"The underlying OS file descriptor, or `-1` on platforms\nthat do not expose one for sockets (such as Windows)."}},"description":"Returns the file descriptor of the bound socket. Ownership remains with the\n`BoundSocket`, so the descriptor must not be closed by the caller. The\ndescriptor is only available before the handle is adopted; afterwards it belongs\nto the adopting [`net.Server`](#class-netserver) or [`net.Socket`](#class-netsocket) and `fd()` throws\n[`ERR_SOCKET_HANDLE_ADOPTED`](errors.html#err_socket_handle_adopted).","summary":"Returns the file descriptor of the bound socket. Ownership remains with the `BoundSocket`, so the descriptor must not be closed by the caller. The descriptor is only available before the handle is adopted; afterwards it belongs to the adopting `net.Server` or `net.Socket` and `fd()` throws `ERR_SOCKET_HANDLE_ADOPTED`.","examples":[],"children":[]},{"kind":"method","id":"boundsocketclose","name":"close","title":"`boundSocket.close()`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Releases the bound socket. Only needed when the handle is never adopted.","summary":"Releases the bound socket. Only needed when the handle is never adopted.","examples":[],"children":[]},{"kind":"method","id":"boundsocketsymboldispose","name":"[Symbol.dispose]","title":"`boundSocket[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v26.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Closes the handle if it has not been adopted or closed; otherwise a no-op.","summary":"Closes the handle if it has not been adopted or closed; otherwise a no-op.","examples":[],"children":[]}]},{"kind":"method","id":"netconnect","name":"connect","title":"`net.connect()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Aliases to\n[`net.createConnection()`](#netcreateconnection).\n\nPossible signatures:\n\n* [`net.connect(options[, connectListener])`](#netconnectoptions-connectlistener)\n* [`net.connect(path[, connectListener])`](#netconnectpath-connectlistener) for [IPC](#ipc-support)\n  connections.\n* [`net.connect(port[, host][, connectListener])`](#netconnectport-host-connectlistener)\n  for TCP connections.","summary":"Aliases to `net.createConnection()`.","examples":[],"children":[{"kind":"method","id":"netconnectoptions-connectlistener","name":"connect","title":"`net.connect(options[, connectListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Alias to\n[`net.createConnection(options[, connectListener])`](#netcreateconnectionoptions-connectlistener).","summary":"Alias to `net.createConnection(options[, connectListener])`.","examples":[],"children":[]},{"kind":"method","id":"netconnectpath-connectlistener","name":"connect","title":"`net.connect(path[, connectListener])`","scope":"module","overloadOf":"netconnectoptions-connectlistener","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Alias to\n[`net.createConnection(path[, connectListener])`](#netcreateconnectionpath-connectlistener).","summary":"Alias to `net.createConnection(path[, connectListener])`.","examples":[],"children":[]},{"kind":"method","id":"netconnectport-host-connectlistener","name":"connect","title":"`net.connect(port[, host][, connectListener])`","scope":"module","overloadOf":"netconnectoptions-connectlistener","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":""}},"description":"Alias to\n[`net.createConnection(port[, host][, connectListener])`](#netcreateconnectionport-host-connectlistener).","summary":"Alias to `net.createConnection(port[, host][, connectListener])`.","examples":[],"children":[]}]},{"kind":"method","id":"netcreateconnection","name":"createConnection","title":"`net.createConnection()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"A factory function, which creates a new [`net.Socket`](#class-netsocket),\nimmediately initiates connection with [`socket.connect()`](#socketconnect),\nthen returns the `net.Socket` that starts the connection.\n\nWhen the connection is established, a [`'connect'`](#event-connect) event will be emitted\non the returned socket. The last parameter `connectListener`, if supplied,\nwill be added as a listener for the [`'connect'`](#event-connect) event **once**.\n\nPossible signatures:\n\n* [`net.createConnection(options[, connectListener])`](#netcreateconnectionoptions-connectlistener)\n* [`net.createConnection(path[, connectListener])`](#netcreateconnectionpath-connectlistener)\n  for [IPC](#ipc-support) connections.\n* [`net.createConnection(port[, host][, connectListener])`](#netcreateconnectionport-host-connectlistener)\n  for TCP connections.\n\nThe [`net.connect()`](#netconnect) function is an alias to this function.","summary":"A factory function, which creates a new `net.Socket`, immediately initiates connection with `socket.connect()`, then returns the `net.Socket` that starts the connection.","examples":[],"children":[{"kind":"method","id":"netcreateconnectionoptions-connectlistener","name":"createConnection","title":"`net.createConnection(options[, connectListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Required. Will be passed to both the\n[`new net.Socket([options])`](#new-netsocketoptions) call and the\n[`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener)\nmethod.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of the\n[`net.createConnection()`](#netcreateconnection) functions. If supplied, will be added as\na listener for the [`'connect'`](#event-connect) event on the returned socket once.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The newly created socket used to start the connection."}},"description":"For available options, see\n[`new net.Socket([options])`](#new-netsocketoptions)\nand [`socket.connect(options[, connectListener])`](#socketconnectoptions-connectlistener).\n\nAdditional options:\n\n* `handle` {net.BoundSocket} A pre-bound [`BoundSocket`](#class-netboundsocket) used as the\n  connection's source binding, honoring its local address and port. Adoption\n  consumes the bound socket (see [ownership transfer](#class-netboundsocket)).\n* `timeout` {number} If set, will be used to call\n  [`socket.setTimeout(timeout)`](#socketsettimeouttimeout-callback) after the socket is created, but before\n  it starts the connection.\n\nFollowing is an example of a client of the echo server described\nin the [`net.createServer()`](#netcreateserveroptions-connectionlistener) section:\n\n```mjs\nimport net from 'node:net';\nconst client = net.createConnection({ port: 8124 }, () => {\n  // 'connect' listener.\n  console.log('connected to server!');\n  client.write('world!\\r\\n');\n});\nclient.on('data', (data) => {\n  console.log(data.toString());\n  client.end();\n});\nclient.on('end', () => {\n  console.log('disconnected from server');\n});\n```\n\n```cjs\nconst net = require('node:net');\nconst client = net.createConnection({ port: 8124 }, () => {\n  // 'connect' listener.\n  console.log('connected to server!');\n  client.write('world!\\r\\n');\n});\nclient.on('data', (data) => {\n  console.log(data.toString());\n  client.end();\n});\nclient.on('end', () => {\n  console.log('disconnected from server');\n});\n```\n\nTo connect on the socket `/tmp/echo.sock`:\n\n```js\nconst client = net.createConnection({ path: '/tmp/echo.sock' });\n```\n\nFollowing is an example of a client using the `port` and `onread`\noption. In this case, the `onread` option will be only used to call\n`new net.Socket([options])` and the `port` option will be used to\ncall `socket.connect(options[, connectListener])`.\n\n```mjs\nimport net from 'node:net';\nimport { Buffer } from 'node:buffer';\nnet.createConnection({\n  port: 8124,\n  onread: {\n    // Reuses a 4KiB Buffer for every read from the socket.\n    buffer: Buffer.alloc(4 * 1024),\n    callback: function(nread, buf) {\n      // Received data is available in `buf` from 0 to `nread`.\n      console.log(buf.toString('utf8', 0, nread));\n    },\n  },\n});\n```\n\n```cjs\nconst net = require('node:net');\nnet.createConnection({\n  port: 8124,\n  onread: {\n    // Reuses a 4KiB Buffer for every read from the socket.\n    buffer: Buffer.alloc(4 * 1024),\n    callback: function(nread, buf) {\n      // Received data is available in `buf` from 0 to `nread`.\n      console.log(buf.toString('utf8', 0, nread));\n    },\n  },\n});\n```","summary":"For available options, see `new net.Socket([options])` and `socket.connect(options[, connectListener])`.","examples":[{"language":"mjs","displayName":null,"code":"import net from 'node:net';\nconst client = net.createConnection({ port: 8124 }, () => {\n  // 'connect' listener.\n  console.log('connected to server!');\n  client.write('world!\\r\\n');\n});\nclient.on('data', (data) => {\n  console.log(data.toString());\n  client.end();\n});\nclient.on('end', () => {\n  console.log('disconnected from server');\n});"},{"language":"cjs","displayName":null,"code":"const net = require('node:net');\nconst client = net.createConnection({ port: 8124 }, () => {\n  // 'connect' listener.\n  console.log('connected to server!');\n  client.write('world!\\r\\n');\n});\nclient.on('data', (data) => {\n  console.log(data.toString());\n  client.end();\n});\nclient.on('end', () => {\n  console.log('disconnected from server');\n});"},{"language":"js","displayName":null,"code":"const client = net.createConnection({ path: '/tmp/echo.sock' });"},{"language":"mjs","displayName":null,"code":"import net from 'node:net';\nimport { Buffer } from 'node:buffer';\nnet.createConnection({\n  port: 8124,\n  onread: {\n    // Reuses a 4KiB Buffer for every read from the socket.\n    buffer: Buffer.alloc(4 * 1024),\n    callback: function(nread, buf) {\n      // Received data is available in `buf` from 0 to `nread`.\n      console.log(buf.toString('utf8', 0, nread));\n    },\n  },\n});"},{"language":"cjs","displayName":null,"code":"const net = require('node:net');\nnet.createConnection({\n  port: 8124,\n  onread: {\n    // Reuses a 4KiB Buffer for every read from the socket.\n    buffer: Buffer.alloc(4 * 1024),\n    callback: function(nread, buf) {\n      // Received data is available in `buf` from 0 to `nread`.\n      console.log(buf.toString('utf8', 0, nread));\n    },\n  },\n});"}],"children":[]},{"kind":"method","id":"netcreateconnectionpath-connectlistener","name":"createConnection","title":"`net.createConnection(path[, connectListener])`","scope":"module","overloadOf":"netcreateconnectionoptions-connectlistener","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Path the socket should connect to. Will be passed to\n[`socket.connect(path[, connectListener])`](#socketconnectpath-connectlistener).\nSee [Identifying paths for IPC connections](#identifying-paths-for-ipc-connections).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of the\n[`net.createConnection()`](#netcreateconnection) functions, an \"once\" listener for the\n`'connect'` event on the initiating socket. Will be passed to\n[`socket.connect(path[, connectListener])`](#socketconnectpath-connectlistener).","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The newly created socket used to start the connection."}},"description":"Initiates an [IPC](#ipc-support) connection.\n\nThis function creates a new [`net.Socket`](#class-netsocket) with all options set to default,\nimmediately initiates connection with\n[`socket.connect(path[, connectListener])`](#socketconnectpath-connectlistener),\nthen returns the `net.Socket` that starts the connection.","summary":"Initiates an IPC connection.","examples":[],"children":[]},{"kind":"method","id":"netcreateconnectionport-host-connectlistener","name":"createConnection","title":"`net.createConnection(port[, host][, connectListener])`","scope":"module","overloadOf":"netcreateconnectionoptions-connectlistener","stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Port the socket should connect to. Will be passed to\n[`socket.connect(port[, host][, connectListener])`](#socketconnectport-host-connectlistener).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Host the socket should connect to. Will be passed to\n[`socket.connect(port[, host][, connectListener])`](#socketconnectport-host-connectlistener).","default":"'localhost'","optional":true,"rest":false,"properties":[]},{"name":"connectListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Common parameter of the\n[`net.createConnection()`](#netcreateconnection) functions, an \"once\" listener for the\n`'connect'` event on the initiating socket. Will be passed to\n[`socket.connect(port[, host][, connectListener])`](#socketconnectport-host-connectlistener).","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Socket","links":[{"name":"net.Socket","href":"net.html#class-netsocket","start":0,"end":10}]},"description":"The newly created socket used to start the connection."}},"description":"Initiates a TCP connection.\n\nThis function creates a new [`net.Socket`](#class-netsocket) with all options set to default,\nimmediately initiates connection with\n[`socket.connect(port[, host][, connectListener])`](#socketconnectport-host-connectlistener),\nthen returns the `net.Socket` that starts the connection.","summary":"Initiates a TCP connection.","examples":[],"children":[]}]},{"kind":"method","id":"netcreateserveroptions-connectionlistener","name":"createServer","title":"`net.createServer([options][, connectionListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.1.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47405","commit":null,"description":"The `highWaterMark` option is supported now."},{"versions":["v17.7.0","v16.15.0"],"prUrl":"https://github.com/nodejs/node/pull/41310","commit":null,"description":"The `noDelay`, `keepAlive`, and `keepAliveInitialDelay` options are supported now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"allowHalfOpen","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `false`, then the socket will\nautomatically end the writable side when the readable side ends.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"highWaterMark","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optionally overrides all [`net.Socket`](#class-netsocket)s'\n`readableHighWaterMark` and `writableHighWaterMark`.","default":"See `stream.getDefaultHighWaterMark()`","optional":true,"rest":false,"properties":[]},{"name":"keepAlive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it enables keep-alive functionality\non the socket immediately after a new incoming connection is received,\nsimilarly on what is done in [`socket.setKeepAlive()`](#socketsetkeepalive).","default":"false","optional":true,"rest":false,"properties":[]},{"name":"keepAliveInitialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If set to a positive number, it sets the\ninitial delay before the first keepalive probe is sent on an idle socket.","default":"0","optional":true,"rest":false,"properties":[]},{"name":"noDelay","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it disables the use of Nagle's\nalgorithm immediately after a new incoming connection is received.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"pauseOnConnect","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Indicates whether the socket should be\npaused on incoming connections.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"blockList","type":{"text":"net.BlockList","links":[{"name":"net.BlockList","href":"net.html#class-netblocklist","start":0,"end":13}]},"description":"`blockList` can be used for disabling inbound\naccess to specific IP addresses, IP ranges, or IP subnets. This does not\nwork if the server is behind a reverse proxy, NAT, etc. because the address\nchecked against the block list is the address of the proxy, or the one\nspecified by the NAT.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"connectionListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Automatically set as a listener for the\n[`'connection'`](#event-connection) event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":""}},"description":"Creates a new TCP or [IPC](#ipc-support) server.\n\nIf `allowHalfOpen` is set to `true`, when the other end of the socket\nsignals the end of transmission, the server will only send back the end of\ntransmission when [`socket.end()`](#socketenddata-encoding-callback) is explicitly called. For example, in the\ncontext of TCP, when a FIN packet is received, a FIN packet is sent\nback only when [`socket.end()`](#socketenddata-encoding-callback) is explicitly called. Until then the\nconnection is half-closed (non-readable but still writable). See [`'end'`](#event-end)\nevent and [RFC 1122](https://tools.ietf.org/html/rfc1122) (section 4.2.2.13) for more information.\n\nIf `pauseOnConnect` is set to `true`, then the socket associated with each\nincoming connection will be paused, and no data will be read from its handle.\nThis allows connections to be passed between processes without any data being\nread by the original process. To begin reading data from a paused socket, call\n[`socket.resume()`](#socketresume).\n\nThe server can be a TCP server or an [IPC](#ipc-support) server, depending on what it\n[`listen()`](#serverlisten) to.\n\nHere is an example of a TCP echo server which listens for connections\non port 8124:\n\n```mjs\nimport net from 'node:net';\nconst server = net.createServer((c) => {\n  // 'connection' listener.\n  console.log('client connected');\n  c.on('end', () => {\n    console.log('client disconnected');\n  });\n  c.write('hello\\r\\n');\n  c.pipe(c);\n});\nserver.on('error', (err) => {\n  throw err;\n});\nserver.listen(8124, () => {\n  console.log('server bound');\n});\n```\n\n```cjs\nconst net = require('node:net');\nconst server = net.createServer((c) => {\n  // 'connection' listener.\n  console.log('client connected');\n  c.on('end', () => {\n    console.log('client disconnected');\n  });\n  c.write('hello\\r\\n');\n  c.pipe(c);\n});\nserver.on('error', (err) => {\n  throw err;\n});\nserver.listen(8124, () => {\n  console.log('server bound');\n});\n```\n\nTest this by using `telnet`:\n\n```bash\ntelnet localhost 8124\n```\n\nTo listen on the socket `/tmp/echo.sock`:\n\n```js\nserver.listen('/tmp/echo.sock', () => {\n  console.log('server bound');\n});\n```\n\nUse `nc` to connect to a Unix domain socket server:\n\n```bash\nnc -U /tmp/echo.sock\n```","summary":"Creates a new TCP or IPC server.","examples":[{"language":"mjs","displayName":null,"code":"import net from 'node:net';\nconst server = net.createServer((c) => {\n  // 'connection' listener.\n  console.log('client connected');\n  c.on('end', () => {\n    console.log('client disconnected');\n  });\n  c.write('hello\\r\\n');\n  c.pipe(c);\n});\nserver.on('error', (err) => {\n  throw err;\n});\nserver.listen(8124, () => {\n  console.log('server bound');\n});"},{"language":"cjs","displayName":null,"code":"const net = require('node:net');\nconst server = net.createServer((c) => {\n  // 'connection' listener.\n  console.log('client connected');\n  c.on('end', () => {\n    console.log('client disconnected');\n  });\n  c.write('hello\\r\\n');\n  c.pipe(c);\n});\nserver.on('error', (err) => {\n  throw err;\n});\nserver.listen(8124, () => {\n  console.log('server bound');\n});"},{"language":"bash","displayName":null,"code":"telnet localhost 8124"},{"language":"js","displayName":null,"code":"server.listen('/tmp/echo.sock', () => {\n  console.log('server bound');\n});"},{"language":"bash","displayName":null,"code":"nc -U /tmp/echo.sock"}],"children":[]},{"kind":"method","id":"netgetdefaultautoselectfamily","name":"getDefaultAutoSelectFamily","title":"`net.getDefaultAutoSelectFamily()`","scope":"module","overloadOf":null,"stability":null,"added":["v19.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"The current default value of the `autoSelectFamily` option."}},"description":"Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`](#socketconnectoptions-connectlistener).\nThe initial default value is `true`, unless the command line option\n`--no-network-family-autoselection` is provided.","summary":"Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`. The initial default value is `true`, unless the command line option `--no-network-family-autoselection` is provided.","examples":[],"children":[]},{"kind":"method","id":"netsetdefaultautoselectfamilyvalue","name":"setDefaultAutoSelectFamily","title":"`net.setDefaultAutoSelectFamily(value)`","scope":"module","overloadOf":null,"stability":null,"added":["v19.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"value","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"The new default value.\nThe initial default value is `true`, unless the command line option\n`--no-network-family-autoselection` is provided.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`](#socketconnectoptions-connectlistener).","summary":"Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`.","examples":[],"children":[]},{"kind":"method","id":"netgetdefaultautoselectfamilyattempttimeout","name":"getDefaultAutoSelectFamilyAttemptTimeout","title":"`net.getDefaultAutoSelectFamilyAttemptTimeout()`","scope":"module","overloadOf":null,"stability":null,"added":["v19.8.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The current default value of the `autoSelectFamilyAttemptTimeout` option."}},"description":"Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`](#socketconnectoptions-connectlistener).\nThe initial default value is `500` or the value specified via the command line\noption `--network-family-autoselection-attempt-timeout`.","summary":"Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`. The initial default value is `500` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`.","examples":[],"children":[]},{"kind":"method","id":"netsetdefaultautoselectfamilyattempttimeoutvalue","name":"setDefaultAutoSelectFamilyAttemptTimeout","title":"`net.setDefaultAutoSelectFamilyAttemptTimeout(value)`","scope":"module","overloadOf":null,"stability":null,"added":["v19.8.0","v18.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"value","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The new default value, which must be a positive number. If the number is less than `10`,\nthe value `10` is used instead. The initial default value is `250` or the value specified via the command line\noption `--network-family-autoselection-attempt-timeout`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`](#socketconnectoptions-connectlistener).","summary":"Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.","examples":[],"children":[]},{"kind":"method","id":"netisipinput","name":"isIP","title":"`net.isIP(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":""}},"description":"Returns `6` if `input` is an IPv6 address, including an IPv4-mapped IPv6 address.\nReturns `4` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no\nleading zeroes. Otherwise, returns `0`.\n\n```js\nnet.isIP('::1'); // returns 6\nnet.isIP('::ffff:127.0.0.1'); // returns 6\nnet.isIP('127.0.0.1'); // returns 4\nnet.isIP('127.000.000.001'); // returns 0\nnet.isIP('127.0.0.1/24'); // returns 0\nnet.isIP('fhqwhgads'); // returns 0\n```","summary":"Returns `6` if `input` is an IPv6 address, including an IPv4-mapped IPv6 address. Returns `4` if `input` is an IPv4 address in dot-decimal notation with no leading zeroes. Otherwise, returns `0`.","examples":[{"language":"js","displayName":null,"code":"net.isIP('::1'); // returns 6\nnet.isIP('::ffff:127.0.0.1'); // returns 6\nnet.isIP('127.0.0.1'); // returns 4\nnet.isIP('127.000.000.001'); // returns 0\nnet.isIP('127.0.0.1/24'); // returns 0\nnet.isIP('fhqwhgads'); // returns 0"}],"children":[]},{"kind":"method","id":"netisipv4input","name":"isIPv4","title":"`net.isIPv4(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no\nleading zeroes. Otherwise, returns `false`.\n\n```js\nnet.isIPv4('127.0.0.1'); // returns true\nnet.isIPv4('127.000.000.001'); // returns false\nnet.isIPv4('127.0.0.1/24'); // returns false\nnet.isIPv4('fhqwhgads'); // returns false\n```","summary":"Returns `true` if `input` is an IPv4 address in dot-decimal notation with no leading zeroes. Otherwise, returns `false`.","examples":[{"language":"js","displayName":null,"code":"net.isIPv4('127.0.0.1'); // returns true\nnet.isIPv4('127.000.000.001'); // returns false\nnet.isIPv4('127.0.0.1/24'); // returns false\nnet.isIPv4('fhqwhgads'); // returns false"}],"children":[]},{"kind":"method","id":"netisipv6input","name":"isIPv6","title":"`net.isIPv6(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if `input` is an IPv6 address, including an IPv4-mapped IPv6 address.\nOtherwise, returns `false`.\n\n```js\nnet.isIPv6('::1'); // returns true\nnet.isIPv6('::ffff:127.0.0.1'); // returns true\nnet.isIPv6('fhqwhgads'); // returns false\n```","summary":"Returns `true` if `input` is an IPv6 address, including an IPv4-mapped IPv6 address. Otherwise, returns `false`.","examples":[{"language":"js","displayName":null,"code":"net.isIPv6('::1'); // returns true\nnet.isIPv6('::ffff:127.0.0.1'); // returns true\nnet.isIPv6('fhqwhgads'); // returns false"}],"children":[]}]}