1

Okay so I am really new to server-side scripting but love to give it a try. My issue thus far is that when I attempt to launch a file like "hellonode.js" I cannot. I launch node and attempt to access a file from within a folder called new

and I get this error:

console is undefined

however when I use node and manually type the address in I get the intended results the javascript application works completely as intended

I really wanna know why it is I cannot execute Node from within a folder but if I manually go to it each time I can. It is rather frustrating

Yashwardhan Pauranik
  • 5,370
  • 5
  • 42
  • 65
  • Possible duplicate of [Microsoft JScript runtime error : Code : 800A1391 'console' is undefined while running node.js program](https://stackoverflow.com/questions/33975327/microsoft-jscript-runtime-error-code-800a1391-console-is-undefined-while-r) – Sanguinary Oct 02 '18 at 06:39
  • please show your code – noone Oct 02 '18 at 06:39

3 Answers3

1

When you are going to execute a node script the 1st argument to node should be the uri of the script file. so

node path/to/your/nodeScript

path would be absolute or relative to your current working directory.

also you can run a node script by giving only the folder of the node script but you need to create the node script file as index.js

suppose you have a folder name MyFirstNodeScript and inside the folder there is a file named index.js the script would be

console.log('hello world!!!');

now you can run the script by node MyFirstNodeScript but you should be in the parent directory of the MyFirstNodeScript

noone
  • 6,168
  • 2
  • 42
  • 51
0

I'm not sure how you get the error but essentially you just "opened" a .js file in windows, which resulted in windows JScript executing your file instead of node executing your file. Maybe because your node.js file, or do you simple double-click?

Basically if you want a file to double-click to start your server create a short .bat file that contains the working snippet to start your node script. However in reality you usually don't need a thing to double click at all.

Lux
  • 17,835
  • 5
  • 43
  • 73
0

I think you need to give the address to the current file in the directory. It's more of a command line way of executing files rather than a node js convention.

node .\hellonode.js

In Unix (Linux or Mac) command lines it should be like this:

node ./hellonode
p0oker
  • 23
  • 4