I'm working on code which will display log files on my computer to a window with a clickable link to access the contents of the log file. The code shown below is script.js and index.html. srcipt.js reads the files and uses a for loop to format them in html and index.html is just supposed to display the logs to the window. However whenever I press my button all it displays is the word undefined on my window and I'm not sure why.
script.js
const fs = require('fs');
var outputHTML = '';
var logdirname = '.././logs/';
    var alllogs = fs.readdirSync(logdirname, function(err, filenames) {
        if (err) {
            onError(err);
            return console.log("Error");
            }
    });
outputHTML += "<table>";
for (var i = 0; i <= alllogs.length ; i++) {
    let iPlusOne = i+1;
    outputHTML += "<tr><td>";
    outputHTML += "<a href=G:\logs\\" + alllogs[i] + ">Log File " + iPlusOne;
    outputHTML += "</a></td></tr>\n"
}
outputHTML += "</table>";
console.log(outputHTML);
index.html
<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript"
        src="script.js">
    </script>
    
</head>
<body>
    <button onclick= "f()">
        Click To Access Logs
    </button>
    <div>
        <p id="text">
        </p>
    </div>
    
    <script type="text/javascript">
        
        function f() {
            
           document.getElementById("text").innerHTML = outputHTML;
        }
    </script>
</body>
</html>
 
    