Skip to content

Instantly share code, notes, and snippets.

View WinsDominoes's full-sized avatar
👕
Cosplaying

Win WinsDominoes

👕
Cosplaying
View GitHub Profile
@miguelmota
miguelmota / index.js
Created November 18, 2015 16:37
Response progress percentage in Node.js
http.createServer(function(request, response) {
var newFile = fs.createWriteStream('file.txt');
var fileByes = request.header['content-length'];
var uploadedBytes = 0;
request.pipe(newFile);
request.on('data', function(chunk) {
uploadedBytes += chunk.length;
var progress = (uploadedBytes / fileBytes) * 100;
response.write('progress: ' + parseInt(progress, 10) + '%\n')