Why is the wget command to download url so much faster than using node.js 's http module request to download?

try to write a script to download the target url using the request module ( https://www.npmjs.com/package.). request is based on the http module API encapsulation ( https://nodejs.org/api/http.h.), so there should be no extra overhead.

but it is found that the download speed is much slower than using the wget that comes with the system, and it is getting slower and slower.

what is the reason behind this?

Mar.12,2021

wget uses the c language, while nodejs uses the javascript language.

The

c language has to be compiled into machine instructions before it runs, while javascript converts scripts into machine instructions through an interpreter at run time.
this causes the c language to outperform javascript in most cases.

< hr >

in addition, when downloading large files (GB and above), you cannot use code similar to the following

var request = require('request');
request('http://xxx', function (error, response, body) {
    // ...
});

this is likely to cause memory exhaustion, so stream processing, such as

, should be used.
request('http://xxx').pipe(fs.createWriteStream('xxx'))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e462fc-43eeb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e462fc-43eeb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?