c4dslbuilder
Version:
A CLI tool designed to compile a folder structure of markdowns and mermaid files into a site, pdf, single file markdown or a collection of markdowns with links - inspired by c4builder
24 lines (23 loc) • 611 B
JavaScript
import net from 'net';
export async function findAvailablePort(preferredPort) {
let port = preferredPort;
while (true) {
const available = await isPortAvailable(port);
if (available) {
return port;
}
port += 1; // Try next port
}
}
async function isPortAvailable(port) {
return new Promise((resolve) => {
const server = net
.createServer()
.once('error', () => resolve(false))
.once('listening', () => {
server.close();
resolve(true);
})
.listen(port);
});
}