Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter-avila/3726e775a12c84c9bb451967aba71dfa to your computer and use it in GitHub Desktop.
Save peter-avila/3726e775a12c84c9bb451967aba71dfa to your computer and use it in GitHub Desktop.
redirect node.js console output to file
Just run the script in your terminal like this...
node script-file.js > log-file.txt
This tells the shell to write the standard output of the command node script-file.js to your log file instead of the default, which is printing it to the console.
This is called redirection and its very powerful. Say you wanted to write all errors to a separate file...
node script-file.js >log-file.txt 2>error-file.txt
Now all console.log are written to log-file.txt and all console.error are written to error.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment