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

2

3 Answers 3

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

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

1 Comment

Thank you very much, your solution worked. Really appreciate your help
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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.