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

240
Views
download csv to browser downloads node.js

I have this code:

    fs = require("fs");
  var downloadData = "select * from PRODUCTS"
    ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
        if (err) return console.log(err);
        conn.query(downloadData, function (err, rows) {
          if (err) {
            console.log(err);
          }


          const ws = fs.createWriteStream("productsDownloaded.csv");
          const jsonData = JSON.parse(JSON.stringify(rows));
          console.log("jsonData", jsonData);
          fastcsv
            .write(jsonData, { headers: true })
            .on("finish", function() {
              console.log("Write to productsDownloaded.csv successfully!");
            })
            .pipe(ws);


    
            var value = true;

            res.render("edit-products", {
              page_title: "edit-products",
              data: rows,
              userName: req.session.username,
              FN: req.session.firstname,
              LN: req.session.lastname,
              CO: req.session.company,
              value: value,
            });

          conn.close(function () {
            console.log("closing function p1 of delete product");
          });
        });
      });

however, it downloads but it doesn't go anywhere. So when im testing locally it goes into my vs code directory, but i want it to download by the browser, so do i have to send something to the front end? Like if i press the download button and trigger this function, it should download to the users directory. how can i achieve this?

about 4 years ago · Santiago Gelvez
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!