I have a JavaScript file (file.js) that contains the following code:
console.log("Hello World!")
When I run this code in my terminal node file.js
, I get the following output:
Hello World
If I wanted to save this to a file programmatically (not right clicking and clicking save), does anyone know how I can do that?
The only solution I can find on the internet was using JSON.stringify("Hello World!")
, but this doesn't do anything I don't believe (doesn't even output an error).
Reference: How to save the output of a console.log(object) to a file?