node js returning Syntax error: Unexpected identifier

Solution 1:

I think you are already in the the console.

Just follow the steps to fix the error:

1) Try doing CTRL + C couple of times. See if you exit the console

2) Then do node HelloWorld.js

I think you will get your output

When in your node console already, you can simply do require("./HelloWorld.js") to get the output. (Given that you are in the directory that contains this file)

Solution 2:

When I type node HelloWorld.js in the node.js console I get

You should type JavaScript into the Node.js console.

node is a program name. HelloWorld.js is a command line argument. They are not JavaScript.

You should type those into your shell (e.g. Windows Powershell or bash).