Thanks to a friend of mine, I was able to answer my question.
As the solution node script.js > log.txt 2> errors.txt
generates only one file of logs and one file of errors. Putting >>
instead of >
permit to append the logs and errors, but the notion of time is lost.
The SOLUTION is to simply do node script.js >> log-error.txt 2>&1
and it generates one file, where both logs and errors are transcribed into this file.
You have to console.log the date at the top of the script and it makes a reliable log-errors file.
To add the date (it will help beginners) just write this :
var today = new Date(); console.log(today.getDate() + '-' + today.getMonth() + '-' + today.getFullYear() + ' ' + today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds() + '.' + today.getMilliseconds())