title: Array returned in function returns undefined
body: <p>Im trying to obtain an array with the path of the files contained in a directory. When returning the array, it returns "undefined". Here's the code:</p>
  
  <pre><code>var server = require('ws').Server;
  var s = new server({ port : 8080 });
  var fs = require('fs');
  
  function searchImagePath(path){
      var array = [];
      fs.readdir(path, (err, files) =&gt; {
          array = files.map(file =&gt; path + "" + file);
      });
      return array;
  }
  
  s.on('connection', function(ws){
      ws.on('message', function(message){
  
          var pathImageList = searchImagePath("./img/");
          console.log("List: " + pathImageList);
  
      });
  
      ws.on('close', function(){
          console.log("I lost a client");
      });
  
  });
  </code></pre>
  
  <p>It's a really simple question, but I've already spent 1 hour with this problem, and can't find a solution. Thanks</p>