Javascript 启动 node.js 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10577879/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:57:13  来源:igfitidea点击:

Starting a node.js server

javascriptnode.js

提问by test

I recently got into node and I installed it on my localhost. I am using WAMP. I am on Windows Vista.

我最近进入节点并将其安装在我的本地主机上。我正在使用 WAMP。我在 Windows Vista 上。

Anwyay, I installed it. I made a new file in my localhost directory with this being called server.js

Anwyay,我安装了它。我在我的 localhost 目录中创建了一个新文件,它被称为server.js

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {
        'Content-Type': 'text/plain',
        'Access-Control-Allow-Origin' : '*'
    });
    response.end('Hello World\n');
}).listen(1337);

then I went to node and tried typing % node server.jsand all I got was an ellipses. What gives?

然后我去节点并尝试打字% node server.js,我得到的只是一个省略号。是什么赋予了?



UPDATE:I checked my Systems variable and saw that my PATHlists the node.js as C:\Program Files (x86)\nodejs\

更新:我检查了我的 Systems 变量,看到我PATH将 node.js 列为C:\Program Files (x86)\nodejs\

enter image description here

在此处输入图片说明

回答by dwerner

Run cmdand then run node server.js. In your example, you are trying to use the REPL to run your command, which is not going to work. The ellipsis is node.js expecting more tokens before closing the current scope (you can type code in and run it on the fly here)

运行cmd然后运行node server.js。在您的示例中,您尝试使用 REPL 来运行您的命令,但这是行不通的。省略号是 node.js 在关闭当前作用域之前需要更多令牌(您可以在此处输入代码并在此处即时运行)