在处理Node.js中的excel文件中的数据时请求超时

我有一个包含数据的Excel工作表,读取数据后正在处理它。 问题是,即使处理没有完成,请求也会在邮递员中超时。

 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);
                  }

         }
    })

我在哪里弄错了?

lchfeiniao 回答:在处理Node.js中的excel文件中的数据时请求超时

您的API超时是因为文件处理需要时间。 如果您使用的是 express 框架,则默认的API超时时间为 2分钟 您可以做的是增加API的超时时间。

如果您使用Express,那么您可以简单地做到

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')
}

         }
    })
本文链接:https://www.f2er.com/3147339.html

大家都在问