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

102
Visualizações
render page with files in response express

want to send files from server to be rendered in browser in index pug

   extends layout block content h1= 'saved files' #recordings.recordings.row script(src='/javascripts/listrecordings.js')
    function fetchRecordings() {
      fetch('/')
        .then((response) => response.json())
        .then((response) => {
          console.log("response " + response);
          if (response.success && response.files) {
            //remove all previous recordings shown
            recordingsContainer.innerHTML = '';
            response.files.forEach((file) => {
              //create the recording element
              const recordingElement = createRecordingElement(file);
              //add it the the recordings container
              recordingsContainer.appendChild(recordingElement);
            })
          }
        })
        .catch((err) => console.error(err));
    };

And the part of index js:

    router.get('/', (req, res) => {
      let files = fs.readdirSync('./public/upploads');
      console.log(__dirname + " files length  " + files.length);
      files = files.filter((file) => {
        // check that the files are audio files
        const fileNameArr = file.split('.');
        return fileNameArr[fileNameArr.length - 1] === 'mp3';
      }).map((file) => `/${file}`);
      //res.json({ success: true, files });
      res.render('index', files);// stuck here ???

    });

how to do this part to shoot response to index

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think a better way to do it is to return an array of paths of the .mp3 files for example:

['upploads/a.mp3', 'upploads/b.mp3' ]

And in the client just need to load the audio using the url:

http://localhost:3000/upploads/a.mp3

To setup your public directory read this docs.

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