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

256
Views
How to Export a PostgreSQL database table in a .csv file using node.js

I'm trying to make a "COPY TO" querie with my node.js application. The goal is to export a database table in .csv that goes to the user downloads of my application. I first tried to write the database table in an existing file with the following querie :

async function exportDatabase(req, res){
return db.any("COPY tag_7z8eq73 to 'C:\Users\New-rFid-Concept\Documents\BioTech_mathis\tag_7z8eq73.csv' delimiters '|' CSV HEADER")
.then(rows => {
        res.json(rows)
    })
    .catch(error => {
        console.log(error)
    });   
}

But the following error is returning : "A relative path is not allowed to use COPY to a file" which means that I have no permission.

From what I understand I have to write to STDOUT but when I send this querie nothing happens in my debug console in VScode or anything else.

I tried :

"COPY tag_7z8eq73 TO STDOUT csv header"

"COPY tag_7z8eq73 TO STDOUT"

"\copy tag_7z8eq73 TO STDOUT"

and others..

Do you know what would be the query that would allow me to create a .csv file with my node.js application?

about 4 years ago · Juan Pablo Isaza
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!