here is my form.html file:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="public/myfirst.js"></script>
</head>
<body>
<h1>File upload</h1>
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" name="logo"/>
<input type="submit" value="Upload">
</form>
<div id = "visited"></div>
<script type="text/javascript" src="public/myfirst.js">
document.getElementById("visited").innerHTML = totalFiles;
</script>
</body>
</html>
here is my myfirst.js file(want to count number of files in a specific folder called "upload"):
let totalFiles;
var fs = require('fs');
fs.readdir( "upload", (error, files) => {
totalFiles = files.length; // return the number of files
console.log(totalFiles); // print the total number of files
});
I can get the right output of myfirst.js file(a javascript file). But my question is that I want to send the output to form.html file in order to show that value on my website frontend. Buy the way, these two files are under same folder. I tried many ways, but none of them works. What should I do?