Jun-Beom Park Jun-Beom Park - 7 months ago 49
Javascript Question

Node js 'console' error in cmd

I want to use the node.js on the windows. so I install node but I can't execute a .js file. That is my source code. And I atteched the error screen.


console.log("Hello, World!")

enter image description here


This error is happening because your script is not executed with nodejs but with Microsoft jscript.

The command you wrote "node node.js" is executing the file ode.js instead of the nodejs in your system in the same way you can execute cmd by typing cmd instead of cmd.exe.

To fix that you need to do one of those :

  • rename the file to something other than node
  • move the file named node in a subfolder (i.e. src/node.js)
  • associate .js file with nodejs instead of microsoft jscript