N
N
Nwton2016-05-16 21:29:43
JavaScript
Nwton, 2016-05-16 21:29:43

Run nodejs function periodically without memory leak?

It is necessary to store a number in mongo every second. How to implement it?
Wrote a simple function:

function test_save(){
  var item = new Testmodel({
    data: 123
  });

  item.save(function(err, item){
    if(err)throw(err);
    setTimeout(test_save, 1000);
  });
}

I tried to save via setInterval / setTimeout, everything works, but there is a memory leak due to which everything then crashes. Is it possible to somehow clean setTimeout without interrupting the recording?
Or maybe there is something radically different that will help me Periodically run a function without leaking memory?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-05-16
@Nwton

use pm2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question