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

255
Visualizações
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
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