Created
November 18, 2015 16:37
-
-
Save miguelmota/c2ae4b7251cf46673bac to your computer and use it in GitHub Desktop.
Response progress percentage in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment