How to Solve the Problem of Automatic Interruption of nodejs’ Mass Download of Pictures

  node.js, question

The picture list has about 10,000 picture addresses.
When using nodejs to download, there will be inexplicable errors.

The basic code is as follows:

var downloadImage2 = function (src) {
 var iArr = src.split("/");
 var imageName = iArr[iArr.length - 1];
 //console.log("Download begin: "plus imageSrc");
 var download = function(uri, filename, callback) {
 request.head(uri, function(err, res, body) {
 // console.log('content-type:', res.headers['content-type']);
 // console.log('content-length:', res.headers['content-length']);
 if (uri) {request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);  bracket
 Download(src, "./images/ "plus imageName, function() {
 Log ('done:' plus index plus plus);

There are also some puzzling mistakes, sometimes:

 throw er;  // Unhandled 'error' event
 Error: Invalid URI "undefined"
 at Request.init (/Users//dirread/node_modules/request/request.js:275:31)
 at new Request (/Users/dirread/node_modules/request/request.js:129:8)
 at request (/Users/dirread/node_modules/request/index.js:55:10)
 at Request._callback (/Users//down.js:21:11)
 at self.callback (/Users//dirread/node_modules/request/request.js:187:22)
 at emitOne (events.js:96:13)
 at Request.emit (events.js:188:7)

Invalid URI “undefined”
Give src a mistake and do not download the wrong address.