node.js - 定时器函数reactJS和NodeJS

标签 node.js reactjs timer

这是我的计时器模块。它应该在计时器代码的基础上运行代码。

我现在面临的问题是,流程工作得很好,但在设置计时器并假设在流程完成时发送的后端有点不起作用。这是因为我为计时器设置了一个值。但是,如何设置计时器以在上一个计时器/步骤完成后继续执行下一个计时器/步骤?

如果您可以在输出中看到,timer02 似乎找不到该文件。但在后台该文件仍在生成。这是计时器问题仪式吗?我们如何将其设置为当您完成时它将继续执行下一个任务。

...
       app.post(('/timer02'),function(req,res)
         {
          res.send(serverdataTime02);
          console.log(`Timer Result Main (02) :`+ serverdataTime02);
         });
          console.log('1.3  The Retrieved File Is Extracted To JSON Format');
          console.log('...');
          console.log('1.4  Proceeding to List Any File That Is Uploaded To Google Cloud Bucket...');
          console.log('...');
          setTimeout(() => listFiles()
            .then(results =>
                {
                 app.post(('/timer03'),function(req,res)
                   {
                    res.send(serverdataTime03);
                    console.log(`Timer Result Main (03) :`+ serverdataTime03);
                   });
...

这是代码的输出。

enter image description here

大家有什么想法、解决方案或链接吗?真的很感激。

最佳答案

将第一行更改为

app.post('/timer02',function(req,res) {

url 路径周围不应有任何括号。

编辑:

确保将 next() 函数调用添加到之前的路由中。 像这样的东西。

app.get('/', function(req, res, next) {
    res.sendFile(path.join(__dirname, 'index.html'));
    next();
})

app.get('/timer02', function(req,res, next) {
    res.send(serverdataTime02);
    next();
});

关于node.js - 定时器函数reactJS和NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55998047/

相关文章:

javascript - 通过 STOMP 复制事件 Socket.io 和 Node.js

node.js - 无法连接到附加到heroku部署的MongoLab数据库

javascript - React-router hashHistory 推送仅更改 URL

c - 中断C定时器

javascript - 与 Kenwood TH-D72A 的串行端口通信似乎几乎是不可能的。为什么我无法使用 javascript 读取数据?

javascript - 如何在 Mongodb 上获取每天的平均数据?

reactjs - 响应输入 onChange 延迟

javascript - ReactJS 获取动态多个输入中的值

.net - DispatcherTimer 与 WPF 应用程序中用于任务调度程序的常规 Timer

c - 如何在 Linux 中测量时间?