src/g/getPort.js
function isAvailable(port) {
    return new Promise((resolve, reject) => {
        const server = net.createServer();

        server.unref();
        server.on('error', reject);
        const options = {};
        options.port = port;
        server.listen(options, () => {
            const { port } = server.address();
            server.close(() => {
                resolve(port);
            });
        });
    });
}
function isAvailable(port) {
    return new Promise((resolve, reject) => {
        const server = net.createServer();

        server.unref();
        server.on('error', reject);
        const options = {};
        options.port = port;
        server.listen(options, () => {
            const { port } = server.address();
            server.close(() => {
                resolve(port);
            });
        });
    });
}
function isAvailable ( port ) { return new Promise ( ( resolve , reject ) => { const server = net . createServer ( ) ; server . unref ( ) ; server . on ( 'error' , reject ) ; const options = { } ; options . port = port ; server . listen ( options , ( ) => { const { port } = server . address ( ) ; server . close ( ( ) => { resolve ( port ) ; } ) ; } ) ; } ) ; }
Passing 0 will get an available random port.
Passing 0 will get an available random port .