I am new to javascript and have trouble reading a value back from
var ls = require('list-directory-contents');
var movies = [];
ls(__dirname + '/movies', function(error, files){
movies = files;
});
console.log(movies); // logs ---> []
From the code above I can see that the ls function (imported via npm install list-directory-contents) has a callback function - so my problem is lack of understanding these and promises? I am confused as to how can I work with the files? Do I have to write all my code inside the ls function call? That seems a bit nasty?
Any help is greatly appreciated and I apologise in advance if this is too easy to answer :)