Run script

$ node main.js

$ node index.js
$ # OR even
$ node .

Evaluate script

Use --eval flag.

$ node -e 'console.log("Hello, World!")'

Use stdin.

$ echo 'console.log("Hello")' | node

Or using --print flag.

evaluate script and print result

No console logging needed. And only the last expression will be printed.

$ node -p '"hello"'
hello

$ node -p '"hello" + " world"'
hello world
$ node -p '1 + 2'
3
$ node -p '1 + 2; 3 +4 '
7

Interactive

$ node
Welcome to Node.js v14.13.1.
Type ".help" for more information.
>

Force interactive mode.

always enter the REPL even if stdin does not appear to be a terminal

$ node -i
Welcome to Node.js v14.13.1.
Type ".help" for more information.
>

This can be useful to run a script snippet first and then go interactive.

$ node -i -e 'console.log(123)'
123
> 

I couldn’t get it to work with a script though. This exited the script.

$ echo 'console.log("Hello")' > test.js
$ node -i test.js
Hello