Skip to content

Instantly share code, notes, and snippets.

@eddex
Created May 1, 2017 14:02
Show Gist options
  • Select an option

  • Save eddex/520c065156b5b1fc3f7e17278b52fb9f to your computer and use it in GitHub Desktop.

Select an option

Save eddex/520c065156b5b1fc3f7e17278b52fb9f to your computer and use it in GitHub Desktop.

Revisions

  1. eddex created this gist May 1, 2017.
    10 changes: 10 additions & 0 deletions node.js_output_to_file.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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