Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda