2

我正在尝试将两个 node.js 文件上传到 koding.com 并运行它们。

index.js 包含:

var server = require("./server");

server.start();

和 server.js

var http = require("http");
var url = require("url");

function start() {
  function onRequest(request, response) {
    console.log("Request received.");
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
  }

    http.createServer(onRequest).listen(6665, '0.0.0.0');
    console.log("Server has started.");
}

exports.start = start;

我在 vm 终端中输入jstq@vm-0:~$ node Web/IkapNodeJS/index.js 它给了我Server has started. 如果我要去http://jstq.kd.io/IkapNodeJS/index.js - 我看到 index.js 包含。当我将 :6665 添加到该网址时 - 找不到网址。

我如何查看带有 hello world 的页面?

4

1 回答 1

4

If you're running your application on 6665, the you would access it with http://jstq.kd.io:6665/. You should see your Hello world there.

Node does not run like a cgi script; you don't point to the file to run it, you run it with a process (node). When the server is running on a specific port, the content will be available on any address/hostname that points to that machine so long as you specify the proper port.

HTH, Aaron

于 2013-07-07T14:49:54.640 回答