我正在尝试将两个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,如果我要转到http://jstq.kd.io/IkapNodeJS/index.js,它会给我Server has started. -我看到index.js包含。当我将:6665添加到该url时-找不到url。
如何查看带有hello world的页面?
发布于 2013-07-07 22:49:55
如果你在6665上运行你的应用程序,你可以用http://jstq.kd.io:6665/来访问它。您应该会在那里看到您的Hello world。
Node不像cgi脚本那样运行;您不需要指向文件来运行它,而是使用一个进程(node)运行它。当服务器在特定端口上运行时,只要您指定了正确的端口,内容就可以在指向该机器的任何地址/主机名上可用。
HTH,Aaron
https://stackoverflow.com/questions/17511610
复制相似问题