0

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?

shay
  • 1
  • 1
  • I've closed this as a duplicate because you are really vague about what you tried and how it failed. The server-side code you've included goes so far as to require `http` and `express` but you never bother to actually do anything with them while your client-side code has a ` – Quentin Apr 23 '20 at 09:07
  • And I've just noticed that the JS code is the public/myfirst.js script … **you cannot use Node.js APIs in a web browser**. – Quentin Apr 23 '20 at 09:08

0 Answers0