E
E
Egor2015-02-22 03:44:47
JavaScript
Egor, 2015-02-22 03:44:47

How to run a script every 5 minutes in node.js?

Greetings.
There is an application on node.js + express 4.0. Inside the application there is a parser that must be constantly launched after a certain period of time (let's say 5 minutes).
How to implement this in node.js?
PS The first thought was to simply wrap the parser call in setTimeout, but I'm not sure if this is a good solution.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
Timur Shemsedinov, 2015-02-22
@ByKraB

1. Crontab: */5 * * * * /script.sh and run node script.js in the script
2. Do require('child_process').fork('script.js'); and already in script.js do setTimeout
3. Use ready-made solutions from npm, for example node-schedule , node-crontab

D
Dmitry Avilov, 2015-02-22
@TheCreator

setTimeout is a completely normal solution, I did this even for almost daily calls, no problems. Native, simple and reliable.

E
Empty User, 2015-02-22
@dimash07

setInterval

A
Alexander Prozorov, 2015-02-22
@Staltec

Can you please explain to me why setTimeout is not a good solution? I will be very grateful!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question