Javascript Node.js Hello World 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7940858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js Hello World not working
提问by Linas
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.
我正在尝试让我的 node.js Hello World 代码工作。我的问题是,当我尝试在我的节点控制台上运行我的“Hello World”js 脚本文件时,我得到“...”并且它一直重复这个直到我运行.clear
命令。
But when I type my hello code directly into console, everything works just fine... I'm using Windows 7 x64.
但是当我直接在控制台中输入我的 hello 代码时,一切正常......我使用的是 Windows 7 x64。
Here is a screenshot of the result:
这是结果的屏幕截图:
http://i.stack.imgur.com/SJqaQ.png
http://i.stack.imgur.com/SJqaQ.png
回答by Emil Stenstr?m
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.
您正在尝试在节点本身内运行您的程序。您启动程序的控制台用于原始 javascript 代码。你在那里写的那行是要在windows 终端中运行的。在那里尝试相同的命令,它会起作用。
回答by EhevuTov
- click "Start"
- run cmd.exe
- 点击“开始”
- 运行cmd.exe
then run the following commands from the command line:
然后从命令行运行以下命令:
cd c:\Users\Shhinigami\Desktop\
node hello.js
cd c:\用户\Shhinigami\桌面\
节点 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.exe 时,它会打开节点界面。当您使用参数(例如文件名)运行它时,它会尝试执行您作为参数传递的文件。另外,运行:
node -h
节点 -h
回答by Rami Jarrar
from cmd.exe change directory to the script directory, then hit:
从 cmd.exe 更改目录到脚本目录,然后点击:
node hello.js
node hello.js
then from the web browser go to :
然后从网络浏览器转到:
http://127.0.0.1:8000/
http://127.0.0.1:8000/
you'll see the hello world message :)
你会看到 hello world 消息:)
回答by user2892750
Now you just go to [Start > All Programs > Node.js > Node.js command prompt] and then run from there.
现在您只需转到 [开始 > 所有程序 > Node.js > Node.js 命令提示符],然后从那里运行。