I want a javascript function to give me the results as soon as the page loads in. It is returning the list of folder names. I am not a developer so this is something I am making to demo my research to a client and therefore I am running into small issues. In my index.html I have incorporated a js function inside the tag and I call that function in my
tag via a ID like this:
<script>
var list_dir = function(){
const path = require('path');
const fs = require('fs');
//joining path of directory
const directoryPath = path.join(__dirname, 'Images');
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
//listing all files using forEach
files.forEach(function (file) {
// Do whatever you want to do with the file
//let names=file
console.log(file);
});
});
}
</script>
<p id="list_dir>list of folders:</p>