Node CLI tool evaluate string

Viewed 251

Is there any way to evaluate a string of Javascript code using the NodeJS CLI tool?

For example, with Perl it would be perl -e "code", with Python python -c "code", with Ruby ruby -e "code", and with PHP, php -r "code".

Is there any flag with the NodeJS CLI tool to evaluate a string of code like this?

I have seen this question, but it does not help since I am not asking how to pipe scripts.

1 Answers

There is a way to do this. You can do it with the same flag that is used with Perl and Ruby: -e

node -e "code"
Related