2013-07-07 40 views
2

我试图将两个node.js文件上传到koding.com并运行它们。在koding.com上访问nodejs应用程序

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终端[email protected]:~$ node Web/IkapNodeJS/index.js 键入它给了我Server has started. 如果我去到http://jstq.kd.io/IkapNodeJS/index.js - 我看到index.js包含的内容。 当即时添加:6665到该网址 - 找不到网址。

如何查看带有hello世界的页面?

回答

4

如果你在6665上运行你的应用程序,你可以用http://jstq.kd.io:6665/访问它。你应该在那里看到你的Hello world

节点不像cgi脚本那样运行;您不指向该文件来运行它,而是通过一个进程运行它(node)。当服务器在特定端口上运行时,只要您指定了正确的端口,内容就可以在指向该机器的任何地址/主机名上使用。

HTH, 亚伦

+0

我得到了'错误312(净值:: ERR_UNSAFE_PORT):当点击该URL未知error.'。 –

+2

它**应该**这样工作,现在看来koding.com存在问题。以下是关于该主题的讨论:https://koding.com/Activity/nodejs-4。另外,维基:http://kwiki.koding.com/wiki/Nodejs – aaronfay

+0

顺便说一句,如果似乎在私人虚拟机上工作,我目前只在共享环境中有这个问题。 – aaronfay

相关问题