Search code examples
node.jsforever

node-forever seems not working as I expected


// test.js

var util = require('util');

setTimeout(function () {
    util.puts('Throwing error now.');
    throw new Error('User generated fault.');
}, 200);

$ forever start -l ./forever.log -o output.log -e err.log -m 5 -a start test.js

I run the above command, and get:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: test_debug.js

I expect to get 5 error log, but actually I just get one in the err.log. It seems test.js just run one time other than 5 times.

Thanks a lot~


Solution

  • Have a look at the 1st warning:

    warn:    --minUptime not set. Defaulting to: 1000ms
    

    If your app can't stay up for more than a second (and yours would crush after 200ms), forever.js wouldn't try to restart it.

    You can test it by either change the setTimeout to wait for 1001ms, or change the minUptime to something shorter than 200ms.