Given is a file with JavaScript-Code. For example:
1 + 1;
3 + 3;
I want to receive the value of the last expression (which is 6 in this case).
This could be achieved via
node --print "1 + 1; 3 + 3;"
But I cannot pass the code as a string because the code can contain quotes which conflict with the quotes around the code (e.g. node -p "1 + 1; aFunction("string")").
Unfortunately, node's --print parameter cannot deal with files.
Another approach would be to modify the source file. I could use the eval-Function which has the desired behaviour that eval("1 + 1; 3 + 3") returns 6. Unfortunately, I run into the same conflicts with the quotes.
I hope I could make my point clear. I'm looking forward to your answers.
If you're on Linux and maybe MacOS and maybe maybe Windows/Cygwin you can put the code in a file and then try this:
node -p < thefile.js