I just installed Node.js on a new system and wanted to make sure it worked. I tested it with a simple hello world script.
Contents of the node.js file
console.log("Hello node");
Then I attempted to run it:
C:\>node node.js
Which produced the following error:
Script: C:\node.js
Line: 1
Char: 1
Error: 'console' is undefined
Code: 800A1391
Source: Microsoft JScript runtime error
Weird. And Microsoft JScript runtime? Very weird.
Turns out, Windows is trying to run the Javascript, node.js
, not via Node.js but natively in Windows.
If I rename the file hellonode.js
I can reproduce the same error:
C:\>hellonode
Or I can run the intended file via Node.js:
C:\>node hellonode.js
Hello node
I did not realize that the Windows command prompt could/would execute Javascript files natively.
Thanks for this posts! It helped me starting my node.js scripting..
Thanks. I’m so new. This really helped.
Thank you! It really helped me starting on nodeJs
Replace Console with console.
The problem is not the name of the file, the problem is your node installation. Check if your computer environment variables contains the path for the node.exe file.
@Gregory, I beg to differ. The issue is specifically about the Windows path and not the Node.js installation.
The Microsoft docs on start indicate that:
On my current Windows 10 box, my PATHEXT includes
.JS
:From this Microsoft document on Windows path:
Based on this information, Windows must find and run the
node.js
file in the current working directory rather than theC:\Program Files\nodejs\node.exe
.If you are seeing something different, let me know!
Thank you bro !!! (^-^)
Renaming or node app.js did not work for me all I did was went to
done started working fine no issues.
Thank you AbhiSunnysays.
It works fine for me.
Thanks,
Yingzi
Gracias, HabĂa intentado una cantidad de cosas pero al final mi error estaba en el nombre del archivo .js