12 ms·
1) node has a -e option 2) why the cat? It just pipes the stuff through 3) you can use <<< to pipe something to stdin (`node <<< 1+1`)
by johannes1234321 5y ago
1) node has a -e option
2) why the cat? It just pipes the stuff through
3) you can use <<< to pipe something to stdin (`node <<< 1+1`)
- codetrotter 5y agoThey wanted to keep feeding stdin that’s why. Their 2+2 is just a placeholder for something bigger, which could even be several lines of input that they wanted to prepend, followed by manual input. In other words they are talking about initiating a REPL session with some initial input followed by manual input.
- dsherret 5y agoJust to be clear, `deno eval "console.log(5)"` has existed for some time which is similar to `node -e "console.log(5)"`. In this case, the deno repl subcommand's --eval flag provides a cross-platform way to evaluate some setup code before launching into the REPL. This is useful if you alias the command in your shell's initialization file allowing you to easily launch a REPL with everything already setup to your liking. For example: $ alias add_repl='deno repl --eval "const add = (a, b) => a + b"' ... $ add_repl Deno 1.13 exit using ctrl+d or close() > add(1, 2) 3
- lxe 5y agoNode's `-p` option will print the result of the evaluation. $ node -p 1+1 2
- dsherret 5y agoThe equivalent in Deno is: $ deno eval -p "1 + 1" 2