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:
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) => {
array = files.map(file => 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");
});
});
It's a really simple question, but I've already spent 1 hour with this problem, and can't find a solution. Thanks