0

In Linux, if I run the following command in the CLI:

node -e 'console.log( "Hello, world!" );'

I get the expected output:

Hello, world!

However, in Windows, if I run

node -e 'console.log( "Hello, world!" );'

Even though I have Node.js v12.8.0 installed, I get:

SyntaxError: Invalid or unexpected token

How can I run Node.js commands like console.log() from the Windows command prompt?

0

1 Answer 1

1

I'm not sure but seems like a it's just Quotation mark error because this worked for me

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

Image

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, that's crazy! So in Windows, I have to use double quotes to signify the Node.js command while in Linux the opposite is true. Thanks very much for your help. Does anyone know why? It must be something to do with Windows CLI syntax.
I believe its just a windows CMD thing because I tried the above command that you used in Linux in my GIT BASH (its linux based) and i got the desired result as you mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.