Cron and nightmarejs
<p>I can't manage to run my cron with nightmarejs. </p>

<p>The first iteration of the function get_data() works great but after that the cron restarts and the function will not be triggered again.</p>

<p>Also "crawl ended" is never logged.</p>

<p>Do you know what's wrong with my code?</p>

<p>Logs</p>

<pre><code>1
cron
data fetched
2
cron
3
cron
</code></pre>

<p>-</p>

<pre><code>var Nightmare = require('nightmare')
var nightmare = Nightmare({
  typeInterval: 300,
  show: true,
  executionTimeout: 120000,
  gotoTimeout: 120000
});
let data = ""
</code></pre>

<p>-</p>

<pre><code>var get_data = function(){
  return new Promise(function(resolve, reject) {
    nightmare
    .goto('https://url.com')
    .type('[name=email]', '')
    .wait(1000)
    .type('[name=email]', 'myemail')
    .wait(1000)
    .type('[name=password]', '')
    .wait(1000)
    .type('[name=password]', 'mypassword')
    .click('[type=submit]')
    .wait(5000)
    .goto('https://url.com')
    .wait(25000)

    .evaluate(function (page, done) {

      return document.body.innerText
      done()
    })
    .end()
    .then(function (result) {
      data = result
    })
    .then(function(data){
      return fs.writeFile("./data.txt", data, function(err) {
        if(err) {
          console.log(err)
          reject(err)
        }
        resolve(data)
      });
    })
    .catch(function(error){
      reject(error)
    })
  })
}
</code></pre>

<p>-</p>

<pre><code>var i = 0
var job = new CronJob('0 */20 * * * *', function() {
    ++i
    console.log(i)
    console.log("cron")
    get_data()
  }, function () {
    console.log("crawl ended")
  },
  true
);

job.start();
</code></pre>