Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:
www.domain.com/files/
contains 4 images (.jpg)
Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:
www.domain.com/files/
contains 4 images (.jpg)
What you asked for:
fs.readdirSync("./")
For example, in Express:
router.get("/someFiles", function(){
return "<ul>"
+ fs.readdirSync("/path/to/someFiles")
.map(function(fName){
return "<li>"+fName+"</li>";
})
+"</ul>"
;
});
What I understand you are searching for:
No, it isn't possible to get the local directories of the client for obvious security reasons. If you want to receive a file, then use a file input field.
Neither is possible to get the server files natively, because JavaScript is a client side language.