I am trying to run my nodejs app on an Amazon EC2 instance using forever. I installed nodejs npm, and then ran sudo npm install forever -g
.
The installation didn't return any errors, so i go ahead and try running my app using forever start server.js
, but it won't do anything - no output what-so-ever, not even an error.
I also tried forever --help
and just forever
, but none of them giving me any response...
When running my app regularly using nodejs - nodejs init.js
then it works as expected, but i need to get it running using forever
so it won't shut down when i disconnect from the server.
Edit :
Since the only problem i was having was that nodejs was closing when i closed the terminal session to my EC2 server, I solved this by using the linux nohup
command like this :
nohup sudo nodejs server.js &
This kept nodejs running in a child process even after I closed the terminal window.
Thanks for the help though! :)
I was also not receiving any stdout
input from any forever
command and this fix nailed it:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Hope that helps someone.
I don't know if this will help, but as an alternative, you can use upstart
. Create a script like this:
#this is the upstart service task. move it to /etc/init/nodeapp.conf
description "server for Node App"
author "Neels Grobler"
chdir /root/servers/nodeapp
exec node init.js 1>stdout.log 2>stderr.log
respawn
And run it by typing start nodeapp
. To stop type stop nodeapp
. You can also change the script so that the node app starts on system boot etc. More info at upstart.ubuntu.com
You should be using forever start server.js
not just forever server.js
On windows, when you run forever like:
forever start app.js
you can find generated log file in file system at:
C:\Users\USERNAME\.forever\SomeLogFileHere.txt
The log files are regenerated for every running script with unique identicator of each file. You can always check which file belongs to which process by:
forever list