Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
How to read file names and display names to window node js

I'm wondering how I'd be able to read file names from my directory and be able to display them in table form to a window. I already have an attempt I made below but for some reason whenever I run the code all it displays on the window is the word "undefined". I'm not too sure why this is and any help to stop it saying undefined would be greatly appreciated.

script.js

const fs = require('fs');

var outputHTML = '';

var logdirname = '.././logs/';
var alllogs = fs.readdirSync(logdirname, function(err, filenames) {
    if (err) {
        onError(err);
        return;
        }
});

outputHTML += "<table>";
for (var i = 0; i <= alllogs.length ; i++) {
    outputHTML += "<tr>";
    outputHTML += "<td>" + alllogs[i] + "</td>"
    outputHTML += "</tr>";
}
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 Animals
    </button>

    <div>
        <p id="text" style="color:purple;
            font-weight:bold;font-size:20px;">
        </p>
    </div>
    
    <script type="text/javascript">
        

        function f() {
            
           document.getElementById("text").innerHTML = outputHTML;

        }

    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem with your code is that your script is not Node.js it's plain JavaScript and you can't access the filesystem from the browser (from JavaScript) because of security restrictions.

Maybe you could work with the File System Access API. It makes the file handling process with browsers much easier.

Then a popup window could show up where you need to select the files.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda