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

108
Visualizações
Cannot set headers after they are sent to the client while parsing data in node js

I am using csv parser to read csv file and passing received data of csv file to ejs template file to print so the data is in object format, so I have used stringyfy but getting error due to this.

Error:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client:

Node js code

app.get('/', function (req, res, next) {
    fs.createReadStream('./Employee.csv')
        .pipe(csv())
        .on('data', function (rows) {
            try {
            var ParsedData=  data:JSON.stringify(rows);
                 res.render('Emp_details',{data:ParsedData});
            }
            catch (err) {
                //error handler
            }
        })
        .on('end', function () {
            //some final operation
        });


});

Code to print data in ejs template file:

<% for(var i = 1; i<= data1.length; i++) { %>
         <%=i %>
       <% } %>
    
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are getting the error because res.render can only be called once but you are calling it every time the data event fires.

You need to call it where you put the comment //some final operation after collecting all the data.

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