Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run an inline node javascript in command line?

Tags:

node.js

I want to temporarily run the node javascript. For example, like this:

echo console.log(1+1) > tmp.js & node tmp.js & del tmp.js

It works fine. However, I do not like the use of temporary files. Is there any other cleaner way?

For example, I wonder if there is an option for such a function in node.exe

like image 648
enoeht Avatar asked Dec 12 '25 19:12

enoeht


1 Answers

You can use the -e, --eval option: node -e "console.log(1+1)"

Documentation: https://nodejs.org/api/cli.html#cli_e_eval_script

like image 54
mdker Avatar answered Dec 15 '25 12:12

mdker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!