How can I throttle uploads in Node.js / Express 4?
Asked Answered
I

2

6

I would like to throttle file uploads in Express 4. By that I mean the bytes per second, not the number of API calls.

I want to be able to simulate a slow connection for file uploads so I can test out my progress animations.

I only want to limit the file upload endpoint and not the other endpoints. How can I do this?

Ideally, I'd like to add some middleware on the specific endpoint and specify the transfer speed in bytes/s.

Integration answered 20/6, 2015 at 8:39 Comment(7)
node-throttleSoloist
I came across node-throttle during research earlier but didn't know how I can hook that up to express as middleware on a single endpoint.Integration
How are you measuring progress? does it involve a request for more data?Vigil
@Arcath, no, just the standard XMLHttpRequest API.Integration
@BrennanCheung How you have done it...??? I have the very same scenario...Urceolate
@RahmatAli, no but if I had to do it now I would probably look to throttle it outside of Express with some kind of networking layer. If it is just for slowing down the browser there are settings for that now in the Network tab of the Chrome dev tools.Integration
@BrennanCheung Got It... Thanks!Urceolate
M
1

If you are on OSX and just interested in some occasional testing (as opposed to a standardized test response) I'd take a look at the Apple Network Link Conditioner. Here's some info.

Also it appears that recent versions of Chromium and I assume Chrome have built in network throttling options in the dev tools.

Mosaic answered 18/12, 2015 at 22:41 Comment(2)
Unfortunately network link conditioner doesn’t work against localhostWagon
Correct - you can use ngrok/localtunnel etc to get around thatMosaic
I
0

Looks like the Chrome Developer Tools allows you to configure a slower network as well.

Integration answered 19/12, 2015 at 2:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.