Crontab + Forever + node.js + NPM

Posted June 9, 2015 9k views

Hi guys, I cant put my crontab to work. I’m on Ubuntu 14.04x64

So, this is what I did:

.sudo apt-get update
.sudo apt-get install nodejs
.sudo apt-get install npm
.curl | bash
[I reload Putty]
.nvm install 0.12
.npm install steam
[Now I go to filezilla, upload the file.js into root directory]
.nvm use 0.12
.node file.js
[It executes the file.js sucessfuly, I reload Putty]
.nvm use 0.12
.npm install forever -g
.forever start file.js
[It will execute the file.js infinitely]

Now I want a restart to execute this commands. The thing is that “forever start” will not execute if I dont execute the “nvm use 0.12” in first place.

.crontab -e
.*/5 * * * * nvm use 0.12 && forever start file.js
ctrl + x

Result: It doesn’t restarts.

What I’m doing wrong? Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Found the solution myself.

0 * * * * root/.nvm/v0.12.4/bin/node /usr/local/bin/forever restart file.js

Thanks anyway! :)