简体   繁体   English

在nodejs中处理来自excel文件的数据时请求超时

[英]request timeout while processing data from excel file in nodejs

I have an excel sheet with data and I am processing it after reading the data.我有一张带有数据的 excel 表,我在读取数据后正在处理它。 The problem is that, even though the processing is not done it, the request gets timed out in postman.问题是,即使处理没有完成,请求也会在 postman 中超时。

 xlsxj({
          input: filepath,//path of the file
          output: null, // I am not taking any output of the file
          sheet: "Party Master"
        }, async function (err, result) {
          if (err) {
            res.send(err);
          } else {
            try {
                for(let row of result) { // more than 1000 iterations
                await fun1(row);
                await fun2(row);
                await fun3(row);
                }
                return res.send('all done');
             }
              catch(err){
                   console.log(err);
                  }

         }
    })

where am I getting wrong?我哪里错了?

You're API timeout because file processing is taking time.您是 API 超时,因为文件处理需要时间。 If you are using express framework the default API timeout is 2 min what you can do is increase the timeout of the API.如果您使用的是express框架,默认的 API 超时为2 分钟,您可以增加 API 的超时。

If you are using express then you can simply do如果您使用的是快递,那么您可以简单地做

 req.setTimeout(500000); // time in ms

I have found a solution. Return the response in finally block.

xlsxj({
          input: filepath,//path of the file
          output: null, // I am not taking any output of the file
          sheet: "Party Master"
        }, async function (err, result) {
          if (err) {
            res.send(err);
          } else {
            try {
                for(let row of result) { // more than 1000 iterations
                await fun1(row);
                await fun2(row);
                await fun3(row);
                }
                return res.send('all done');
             }
              catch(err){
                   console.log(err);
                  }
finally{
return res.send('all done')
}

         }
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM