Skip to content Skip to sidebar Skip to footer

Using Nodejs's Forever To Output Console.logs To Screen

I just discovered that my nodejs app keeps crashing, so I've used forever app.js to start my app and have it automatically restarted when it crashes. Problem: Now my app outputs al

Solution 1:

Directly with forever command :

forever logs app.js -f

It shows in realtime output of your application and forever logs (shows detected changes & restart messages).

Solution 2:

You can watch a logfile live by using this shell-command.

tail -f /path/to/logfile

Not sure if this is what you needed.

Solution 3:

Simplest way to go is

Run :

forever logs // will give you list of log files
forever logs 0 -f // then just provide the index of log

Solution 4:

If you pass the --help flag to Forever you'll see this example:

forever -o out.log -e err.log my-script.js

-o and -e define the stdout and stderr log files.

-o  OUTFILE      Logs stdout from child script to OUTFILE
-e  ERRFILE      Logs stderr from child script to ERRFILE

Forever seems a little overkill for development. Give Supervisor a shot and see if you like it better:

npm install -g supervisor
supervisor app.js

Solution 5:

I am running nodejs on AWS EC2 instance and this worked for me. Note: logs are accessible if you are root owner. So first use sudo su then

forever -a -o out.log -e err.log yourServerApp.js

It will tail console log (in case you track event messages from log) and error log. I hope it helps someone.

Post a Comment for "Using Nodejs's Forever To Output Console.logs To Screen"