Handles dynamic or forced TCP port allocation for network services. Use this to manage ephemeral port assignment in sidecar processes or microservices.
// Source: https://github.com/nexu-io/open-design | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/**
* @module port
*
* TCP port allocation: a forced port is checked for availability and reserved, or
* a dynamic port is probed via an ephemeral listen until a non-reserved one is
* found. Depends on the shared net primitives and the public port types.
*/
import type { Server } from "node:net";
import { closeServer, listenOnPort } from "./net.js";
import type { PortAllocation, PortRequest } from "./types.js";
/**
* @internal Validate and parse a port value to an integer in 1..65535, or null
* when absent/empty.
*/
function parsePort(value: number | string | null | undefi
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key