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