启动node.js服务器

时间:2012-05-14 05:28:07

标签: javascript node.js

我最近进入了节点,并将其安装在我的localhost上。我正在使用WAMP。我在Windows Vista上。

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);

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


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

enter image description here

1 个答案:

答案 0 :(得分:46)

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

相关问题