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

234
Views
node.js instead of redirect show alert message

I have written a node.js code which is basically uploading a file to desired folder. the code is as shown below:

app.post('/upload', function(req, res) {
    req.pipe(req.busboy);
    req.busboy.on('file', function(fieldname, file, filename) {
        var fstream = fs.createWriteStream('./python_codes/' + filename); 
        file.pipe(fstream);
        fstream.on('close', function () {
            res.send('upload succeeded!');
            console.log("fileuploaded")
        });
    });
});

but on clicking the upload button on client side it is redirecting to new page. instead of redirecting I want to show a alert message. Thanks in advance!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You must be using form with method=POST and action='/upload'to upload the file. When submitted it'll take you to new page with content "upload succeeded!"

To remain on the same page use AJAX on client side to make the POST request. Upon success you can show the server response as alert message.

You can refer:

Uploading both data and files in one form using Ajax?

jQuery Ajax File Upload

over 4 years ago · Santiago Trujillo 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!