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

161
Views
Send an uploaded file to client with node.js

I am new with node.js. Here is my problem: I upload a file from html

<form method="POST" action="/upload" enctype="multipart/form-data"
   <div>
      <input type="file" name="myFile" id="fileUpload" multiple />
    </div>
     <div>
      <input type="submit" name="btn_upload" value="Upload" />
    </div>
  </form>

then I upload the file from directory with multer and parse with the npm pdfParser from pdf to json, the files are regularly copied in the main directory and the code goes back to home page.

try {
  app.post("/upload", (req, res) => {
    upload(req, res, (err) => {
      if (err) {
        console.log(err);
      } else {
        if (req.file == undefined) {
          res.redirect("index.html");
        } else {
          fileOriginale = req.file.originalname;
          const pdfParser = new PDFParser();
          pdfParser.on("pdfParser_dataError", (errData) =>
            console.error(errData.parserError)
          );
          pdfParser.on("pdfParser_dataReady", (pdfData) => {
            const test = fileOriginale.substring(0, fileOriginale.length - 4);
            const id = __dirname + "/" + test + ".json";
            console.log("filetofetch in pdfParser", id);
            fs.writeFile(
              id,
              JSON.stringify(pdfData),
              (err) => console.error(err)
            );
          });
          pdfParser.loadPDF(__dirname + "/" + fileOriginale.toString());
          res.redirect("index.html");
          res.end();
          return;
        }
      }
    });
  });
} catch (err) {
  console.log(err);
  return;
}

Here the issue: How can I parse the .json file loaded in the main directory and send it to the client ?

about 4 years ago · Juan Pablo Isaza
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!