How would I limit upload speed from the server in node.js?

后端 未结 3 2025
清酒与你
清酒与你 2020-12-24 10:14

How would I limit upload speed from the server in node.js?

Is this even an option?

Scenario: I\'m writing some methods to allow users to automated-ly upload

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 10:38

    Use throttle module to control the pipe stream speed

    npm install throttle

    var Throttle = require('throttle');
    
    // create a "Throttle" instance that reads at 1 b/s 
    var throttle = new Throttle(1);
    
    req.pipe(throttle).pipe(gzip).pipe(res);
    

提交回复
热议问题