Answer the question
In order to leave comments, you need to log in
NodeJs how to make a script run automatically on time?
Good day.
- There is a nodejs server, I run the server.js input file on the server through forever start
- There is a script that parses information from the donor site
I wanted to make the parsing happen every half an hour, I used the 'node-schedule' package
But I realized that I did it wrong by putting the code in server.js i.e. each user who came to the site ran the parsing script.
The question is - how to do it right?
Do I understand correctly that you need to run separate processes with parsing and with the site. If possible, please share an example.
Thanks in advance
Answer the question
In order to leave comments, you need to log in
Feng shui: set up cron and run node parser.js
If there is nothing to do: setInterval(function(){/*parse*/}, 30*60*1000)
For example like this:
function parser() {
// request get
return Promise.delay(500).then(() => ({ results: [] }));
}
function* sequence() {
while (true) {
yield parser();
// other throwns
}
}
(async () => {
for (let parserPromise of sequence()) {
const parserResults = await parserPromise;
await Promise.delay(30 * 60 * 1000);
}
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question