First, I apologize if this is an immature question without proper research before asking. My question is, in Nodejs (with Express), for a fileuploading application, what is the best method to response back to client (javascript of the page) the percentage (progress) of the uploading back to the client: My option is either Long Polling or WebSocket (socket.io).
var form = new formidable.IncomingForm(); form.uploadDir = __dirname+ '/uploaded'; res.writeHead(200, { 'Content-type': 'text/plain' }); form.parse(req, function(err, fields, files) { if (err) throw err; // console.log(files); }); form.on('progress', function(bytesReceived, bytesExpected) { var progress = 100*bytesReceived/bytesExpected; console.log(progress); res.write(progress.toString()); });
Which is writing the data back without ending the connection.
So which is the correct and proper solution, and what are theirs drawback?