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

196
Vistas
Piping the response into a variable using streams | Axios | Node.js

I am using Axios to extract data from an API. Since there are so many records, I am trying to pipe the response into a variable. But I am not able to do it.

app.post("/Node", jsonparser, async (req, res) => {
var APIdata;
axios(authOptions)
    .then((response) => {
        response.data.pipe(APIdata);
    })
    .catch((error) => {
        res.send(error);
    });
}

Where as, I am able to send the data as a response to res and get it displayed in the frontend. The code for it is below.

app.post("/Node", jsonparser, async (req, res) => {
axios(authOptions)
    .then((response) => {
        response.data.pipe(res);
    })
    .catch((error) => {
        res.send(error);
    });
}

Could anyone please tell me how we can save the data to a variable? The data needs to be pushed to database...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do something like this,

var APIdata;
axios.get(url, { responseType: "stream" }).then(response => {
const stream = response.data;

stream.on("data", chunk => {
  APIdata.push(chunk)
};

stream.on("end", () => console.log("end of stream", APIdata));
});
about 4 years ago · Juan Pablo Isaza Denunciar
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