2

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.

0

1 Answer 1

6

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" 
Sign up to request clarification or add additional context in comments.

1 Comment

You can use -p to evaluate and print the result.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.