2

I am on OSX and installed node from the website.

When I tried running basic

console.log('Hello World')

it's giving me following error

-bash: syntax error near unexpected token `'Hello world''

Please let me know how do I proceed.

I tried re-installing node from Node Github installation and if I try to check version of node or npm, I can see them.

2 Answers 2

4

Terminal is just a window running Bash (by default) - you are expecting Bash to suddenly understand JavaScript just by installing node.js on your system. You must first switch from Bash to Node by typing node and then you can start executing JavaScript commands.

Hit Ctrl+c twice to exit.

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

Comments

1

You have to run: node yourfilename.js

Or if you want to Access to The REPL: node -i

2 Comments

it's not in file. I'm just running it in Terminal
You can't execute code directly from The terminal. You have to put your code into a file and launch it, or run code interactively using the REPL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.