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

Function tryPort

scripts/dev-safe.mjs:245–253  ·  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

243 * @returns {Promise<boolean>} True if the port is available
244 */
245function tryPort(port, host = "127.0.0.1") {
246 return new Promise((resolve) => {
247 const server = net.createServer();
248 server.once("error", () => resolve(false));
249 server.listen(port, host, () => {
250 server.close(() => resolve(true));
251 });
252 });
253}
254
255/**
256 * 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.45

Tested by

no test coverage detected