No it can't be fixed. Browserify lets you make modules available in the browser that don't depend on core modules provided by node when run as an executable. File system access using the fs
module is one such core module.
While you could perhaps try the draft File API in client side HTML, you would need user interaction to select a directory from a picker and serve the page using https
1 - which if you're running node on a local machine network, may require creating an unsigned security certificate using openSSL. However, if you go down this route the user will need to accept an unsigned security certificate, as well as correctly choosing the image directory, as well as be using a browser that supports yet to be standardized File API.
1Update with thanks to comment from @connexo
The showDirectoryPicker
documentation currently states
This feature is available only in secure contexts (HTTPS)
However, localHost
is being treated as a "secure context" in this regard by Chromium based browsers. Hence creating a security certificate and running a localHost server using HTTPS is not required for supporting browsers (noting Firefox has not implemented the File API as yet).
Also a directory picker cannot be opened programmatically in JavaScript without user interaction via a click or hand gesture event. Some test code to attempt to open a directory picker in various browsing contexts (doesn't work in sandboxed documents):
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<title>Dir Picker</title>
</script>
</head>
<body>
<button type="button" onclick="pick()">Show Directory Picker</button><br>
Did a directory picker open automatically? - See console if not.
<script>"use strict";
async function getDir() {
const dirHandle = await window.showDirectoryPicker();
// console.log(dirHandle);
}
const pick= ()=> {
getDir()
.then(()=>console.log("Picker opened!"))
.catch(err=>console.error("Failed to open picker from inline script:\n" + err.message
+ "\nuserAgent: " + navigator.userAgent));
}
pick(); // automatic attempt
</script>
</body>
</html>
Although the post doesn't cover details of how the HTML page is created, the results obtained are to be used in another HTML page. Depending on the infrastructure in use you could
generate the directory listing in node. If you need to serve it as an HTML page, create an HTML page on the server to do so.
generate the listing manually in a terminal using ls
or dir
commands, depending on operating system, direct the output to a file and text process the results.