Tioww Tioww - 1 month ago 11
Javascript Question

How to write all socket.io server console text into txt file?

My socket server shuts down sometimes and I can't check why because there is no txt log where i could check last error messages, maybe there is way to write it in txt file after shutting down?

Answer

Invoke your program in the following way: node myserver.js 2> error_log.txt

When the program closes the error_log txt will have all messages, including the error message that made the program crash written in it.

To also get all console.log messages you can do node myserver.js > error_log.txt > 2>&1

(I used this command in the bash console on windows)