O
O
odd-look2015-02-27 11:56:13
JavaScript
odd-look, 2015-02-27 11:56:13

How to use setInterval in express js project?

There is a parser function. I want to call it constantly, after a certain period of time.
setInterval(parser(1, 0), 180000);
But the second time I get an error in the console:

timers.js:265
callback.apply(this, args);
^
TypeError: Cannot read property 'apply' of undefined
at wrapper [as _onTimeout] (timers.js:265:13)
at Timer.listOnTimeout (timers.js:110:15)

I am using express-generator. Question: where is it better to shove setInterval, what would work - in routes or in app, so that it is executed during initialization?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
odd-look, 2015-02-27
@odd-look

found a solution, you need to put the parser in function () {}

K
Kir ---, 2015-02-27
@SowingSadness

setInterval has nothing to do with it. You have a logical error. parser(1,0) returns an object, which then becomes undefined for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question