index.js
function listNetInterfaces() {
    return new Promise((ac, rj) => {
        exec('nmcli d', (err, stdout, stderr) => {
            const lines = stdout.split('\n');
            if (err || lines.length<2) {
                rj({error: 'No network available.'});
                return;
            }

            lines.shift();
            // Correct visible APs should be listed
            let bWlanExist = false;
            const interfaces = [];
            lines.forEach((line)=>{
                let sp = line.trim().split(/\s+/);
                if (sp.length < 4 || sp[0]=='lo') return; // Illegally formatted line
                if (sp[0].indexOf('wlan')==0) bWlanExist = true;
                interfaces.push(sp[0]);
            });

            ac([interfaces, bWlanExist]);
        });
    });
}
function listNetInterfaces() {
    return new Promise((ac, rj) => {
        exec('nmcli d', (err, stdout, stderr) => {
            const lines = stdout.split('\n');
            if (err || lines.length<2) {
                rj({error: 'No network available.'});
                return;
            }

            lines.shift();
            // Correct visible APs should be listed
            let bWlanExist = false;
            const interfaces = [];
            lines.forEach((line)=>{
                let sp = line.trim().split(/\s+/);
                if (sp.length < 4 || sp[0]=='lo') return; // Illegally formatted line
                if (sp[0].indexOf('wlan')==0) bWlanExist = true;
                interfaces.push(sp[0]);
            });

            ac([interfaces, bWlanExist]);
        });
    });
}
function listNetInterfaces ( ) { return new Promise ( ( ac , rj ) => { exec ( 'nmcli d' , ( err , stdout , stderr ) => { const lines = stdout . split ( '\n' ) ; if ( err || lines . length < 2 ) { rj ( { error : 'No network available.' } ) ; return ; } lines . shift ( ) ; // Correct visible APs should be listed let bWlanExist = false ; const interfaces = [ ] ; lines . forEach ( ( line ) => { let sp = line . trim ( ) . split ( / \s+ / ) ; if ( sp . length < 4 || sp [ 0 ] == 'lo' ) return ; // Illegally formatted line if ( sp [ 0 ] . indexOf ( 'wlan' ) == 0 ) bWlanExist = true ; interfaces . push ( sp [ 0 ] ) ; } ) ; ac ( [ interfaces , bWlanExist ] ) ; } ) ; } ) ; }
List Network Interfaces
@return {Promise} Return a list of network interfaces and whether you are using WiFi
List Network Interfaces