title: Serialport npm List of available COM ports
body: <p>I'm having a problem with a part of my program and i think I know what the problem is I can't find way to fix it, hence need your help.</p>
  
  <p>I think the problem is not with the serialport.list function but more with the way I am using it.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    var getPortsList= ()=&gt;{
      var portsList = [];
      SerialPort.list((err, ports)=&gt;{
        ports.forEach((ports)=&gt;{
          portsList.push(ports.comName);
          //console.log(portsList);
        });
      });
  
      return portsList;
  
    };
  </code></pre>
  
  <p>So I wraped the list function in my own function and I am calling it when I need to check what ports are available. The problem I'm having is that I always get an empty array returned. If I console.log from inside the forEach i am definitely getting the COM port names and if I console.log from inside the list function after the forEach loop I'm getting the array and is not empty.
  I can only assume this is some issue relating to the concorrent nature of javascript, but I'm not quite sure how to solve this problem.
  I can see this is an important concept that will come up all the time and I would like to understand it a bit better.
  Any info on ways to handle this kind of issue or suitable links would be apreciated.
  Thank you.
  Best Regards
               Luis</p>