Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!