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

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

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 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!