0

I'm trying to get my node.js Hello World code to work. My problem is that when I try to run my "Hello World" js script file on my node console, I get "..." and it keeps repeating this until I run .clear command.

But when I type my hello code directly into console, everything works just fine... I'm using Windows 7 x64.

Here is a screenshot of the result:

https://i.sstatic.net/SJqaQ.png

enter image description here

6
  • 6
    entirely unrelated note: sweet background ^_^ Commented Oct 29, 2011 at 18:39
  • 9
    Post code, not screenshots. Commented Oct 29, 2011 at 18:42
  • 1
    The code in Notepad seems like it's creating a HTTP server – did you try connecting to it in a web browser? Commented Oct 29, 2011 at 18:42
  • Works fine for me; what's the output of which node? Commented Oct 29, 2011 at 18:44
  • Sorry about image i just wanted to show console and code in the same pic, and yeah i tried connecting with browser but nothing happens, but when i run my code directly in a console and try to connect with browser everything works just fine Commented Oct 29, 2011 at 18:45

4 Answers 4

15

You are trying to run your program inside node itself. The console you are starting your program from, is for raw javascript code. The line you wrote there is meant to be run in the windows terminal. Try the same command there and it'll work.

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

5 Comments

Oh, I thought that was just his shell prompt. What's that $? Oh, OP typed in the entire shell line including the prompt?!
Sorry for my stupidity it's my first time trying to work with consoles, so if get that right i should try to run in it in windows cmd? or something else?
@Linas Yes, you should run the comment node hello.js from a windows command prompt (or unix shell).
so, i tried to run "node hello.js" in windows terminal, and i got error "node is not recognized, bla bla bla" so i navigated to my node and ran it, then i tried to run node hello.js and i got same thing "..." i'm not sure what i'm doing wrong and btw i can't seem to find that checkbox ;d
oh i fynaly got that, it's working ^_^, just one problem left how do i check that thingy u want :D
2
  1. click "Start"
  2. run cmd.exe

then run the following commands from the command line:

cd c:\Users\Shhinigami\Desktop\

node hello.js

When you run node.exe by itself, it opens up the node interface. When you run it with an argument, such as a filename, it tries to execute the file you pass as the argument. Also, run:

node -h

Comments

2

from cmd.exe change directory to the script directory, then hit:

node hello.js

then from the web browser go to :

http://127.0.0.1:8000/

you'll see the hello world message :)

Comments

-2

Now you just go to [Start > All Programs > Node.js > Node.js command prompt] and then run from there.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.