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

193
Visualizações
How to send CSV data from Neo4j query results through Node.js/AdonisJs

Currently, I have some code that query from Neo4j database then write to a CSV file on server:

const session = driver.session();
const query = '<my query>';
var file = fs.createWriteStream('export.csv');
file.write('<some CSV header here');
await new Promise((resolve, reject) => {
  session.run(query).subscribe({
    onNext: i => {
      file.write('<data of record i>');
    },
    onCompleted: () => {
      session.close()
      file.end()
      resolve()
    },
    onError: error => {
      console.log(error)
      reject()
    }
  })
})
return response.download('export.csv');

Everything is fine until now I have more data in the database so the process to write a CSV file takes a long time, then the client receives a timeout error.

I have found a couple of solutions that use pipe() to send stream directly to the client but I tried it and failed because the result of session.run() is an observable not stream. Is there any other way?

Note: I'm using AdonisJs for backend

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can write data directly into the response like this:

const session = driver.session();
const query = '<my query>';
response.response.writeHead(200, {
  'Content-Type': 'application/csv',
  'Content-Disposition': 'attachment; filename="export.csv"'
});
response.response.write('<some CSV header here');
await new Promise((resolve, reject) => {
  const results = session.run(query).subscribe({
    onNext: i => {
      response.response.write('<data of record i>');
    },
    onCompleted: () => {
      session.close()
      response.response.end()
      resolve()
    },
    onError: error => {
      console.log(error)
      reject()
    }
  })
})
over 4 years ago · Santiago Trujillo 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