How not to run a query within 30 minutes?

Express sends a request to third party api for getting data and writes them to a file how to do that in 30 minutes the file was not updated and not sent the request to third party api?
March 19th 20 at 08:52
2 answers
March 19th 20 at 08:54
Solution
let lastRequested = new Date()

if (new Date() - lastRequested > 1000 * 60 * 30) { // 1000 MS * 60 sec * 30 min.
 lastRequested = new Date()
 // here is the query
//
 // better yet upgrade lastRequested = new Date()
 // when a request returns successfully
 // in case of failure it can be repeated faster than half an hour
}
March 19th 20 at 08:56
Solution
To save the time of the last request and check if it passed 30 minutes since the last request. If it is, then run the query and save the new value.

Find more questions by tags Express.jsNode.js