lib/find.js
function find () {
  const serialPath = this.paths.linux.serial;
  const readLink = (file, filePath) => (
    new Promise((resolve, reject) => {
      fs.readlink(filePath, (error, link) => {
        if (error) {
          reject(error);
        } else {
          resolve({
            'info': file.replace(/\_/g, ' '),
            'port': path.resolve(serialPath, link)
          });
        }
      });
    })
  );
  const readDir = (directory) => (
    new Promise((resolve, reject) => {
      fs.readdir(directory, (error, files) => {
        if (error) {
          reject(error);
        } else {
          resolve(files);
        }
      });
    })
  );

  return new Promise(async (resolve, reject) => {
    try {
      const files = await readDir(this.paths.linux.serial);

      if (!files.length) {
        // Resolve if the directory is empty
        resolve([]);
      }

      let promises = [];
      files.forEach((file) => {
        const filePath = path.join(serialPath, file);
        promises.push(readLink(file, filePath));
      });

      // Wait for all promisses to be resolved
      this.ports = await Promise.all(promises);

      resolve(this.ports);
    } catch (error) {
      reject(error);
    }
  });
}
function find () {
  const serialPath = this.paths.linux.serial;
  const readLink = (file, filePath) => (
    new Promise((resolve, reject) => {
      fs.readlink(filePath, (error, link) => {
        if (error) {
          reject(error);
        } else {
          resolve({
            'info': file.replace(/\_/g, ' '),
            'port': path.resolve(serialPath, link)
          });
        }
      });
    })
  );
  const readDir = (directory) => (
    new Promise((resolve, reject) => {
      fs.readdir(directory, (error, files) => {
        if (error) {
          reject(error);
        } else {
          resolve(files);
        }
      });
    })
  );

  return new Promise(async (resolve, reject) => {
    try {
      const files = await readDir(this.paths.linux.serial);

      if (!files.length) {
        // Resolve if the directory is empty
        resolve([]);
      }

      let promises = [];
      files.forEach((file) => {
        const filePath = path.join(serialPath, file);
        promises.push(readLink(file, filePath));
      });

      // Wait for all promisses to be resolved
      this.ports = await Promise.all(promises);

      resolve(this.ports);
    } catch (error) {
      reject(error);
    }
  });
}
function find ( ) { const serialPath = this . paths . linux . serial ; const readLink = ( file , filePath ) => ( new Promise ( ( resolve , reject ) => { fs . readlink ( filePath , ( error , link ) => { if ( error ) { reject ( error ) ; } else { resolve ( { 'info' : file . replace ( / \_ / g , ' ' ) , 'port' : path . resolve ( serialPath , link ) } ) ; } } ) ; } ) ) ; const readDir = ( directory ) => ( new Promise ( ( resolve , reject ) => { fs . readdir ( directory , ( error , files ) => { if ( error ) { reject ( error ) ; } else { resolve ( files ) ; } } ) ; } ) ) ; return new Promise ( async ( resolve , reject ) => { try { const files = await readDir ( this . paths . linux . serial ) ; if ( ! files . length ) { // Resolve if the directory is empty resolve ( [ ] ) ; } let promises = [ ] ; files . forEach ( ( file ) => { const filePath = path . join ( serialPath , file ) ; promises . push ( readLink ( file , filePath ) ) ; } ) ; // Wait for all promisses to be resolved this . ports = await Promise . all ( promises ) ; resolve ( this . ports ) ; } catch ( error ) { reject ( error ) ; } } ) ; }
Find all registered serial ports by-id

@return {Promise<Object[]|Error>}
Find all registered serial ports by - id