Home > Mobile >  Node.js Logging to File deleting old log on restart
Node.js Logging to File deleting old log on restart

Time:12-05

I have a Node.js Application that I execute with systemctl start app.service on my server. I configured my package.json correctly that on app start the log is being written in app.log with node app.js > app.log 2>&1 the problem is now that with every restart the old log is being deleted and a new one is genereted. I want to keep my old log data for debugging purposes. How can I edit the log statement that the old log will be saved or the new log just appended? Is this possible?

I already searched in Stackoverflow and Google for a solution but did not find one. I was expecting to keep my old logs.

CodePudding user response:

When using IO redirection, if you want to append to a file rather than overwrite the file, you need to use ">>" instead of ">". For example:

node app.js >> app.log
  • Related