MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / tryPort

Function tryPort

scripts/dev-safe.mjs:235–243  ·  view source on GitHub ↗

* Check if a port is available by attempting to bind to it. * * @param {number} port - The port to check * @param {string} host - The host to bind to * @returns {Promise } True if the port is available

(port, host = "127.0.0.1")

Source from the content-addressed store, hash-verified

233 * @returns {Promise<boolean>} True if the port is available
234 */
235function tryPort(port, host = "127.0.0.1") {
236 return new Promise((resolve) => {
237 const server = net.createServer();
238 server.once("error", () => resolve(false));
239 server.listen(port, host, () => {
240 server.close(() => resolve(true));
241 });
242 });
243}
244
245/**
246 * Assert that all listed ports are available, throwing a descriptive error if

Callers 3

findFreePortFunction · 0.85
assertPortsFreeFunction · 0.85
findFreePortsFunction · 0.85

Calls 1

closeMethod · 0.80

Tested by

no test coverage detected