Home > Back-end >  node.js : How to combine a server that does post requests on a timed basis, with a server which list
node.js : How to combine a server that does post requests on a timed basis, with a server which list

Time:01-10

So I am working on a project where there is a program like the following:

async function watch(){
    "does post requests"
}
async function timer() {
    await watch();
};
let tmr = setInterval(function(){ timer() }, 6 * 1000);

async function main() {
   "does event listening"
}
main()

and it is very clunky.

I am wondering if there are any node wizards here that can help with this sort of architecture problem?

I.e. How to combine a server that does post requests on a timed basis, with a server which listens for events.

CodePudding user response:

What might interest you is: https://www.npmjs.com/package/node-cron

You could simply create the http server and declare routes to receive requests, and configure node cron-job that will send requests of your choice on a timed basis.

  •  Tags:  
  • Related