Answer the question
In order to leave comments, you need to log in
How to create an eternal process in node.js?
The task is as follows: every second a random number is generated on the server and stored in the database. Constantly, even if there is not a single client.
What is the best way to implement this? The first thing that comes to mind is to write a simple generate+save function. into the database and at the end of execution with a delay of 1 second, run it again, recurse.
Is this an adequate solution, even if it turns out to dodge and create a recursion? Or is it possible in some other way? Which way to look?
I am new to node.js.
Answer the question
In order to leave comments, you need to log in
setInterval(function() {
db.write({ }); // пишем в базу каждую секунду
}, 1000);
As for setInterval, Alexander Wolf
already suggested.
On my own, I’ll add another tip to get acquainted with such a utility as pm2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question