Node.js导出模块无法正常工作

时间:2013-11-22 12:21:42

标签: javascript node.js

我是node.js的初学者,我找到了一个学习的教程。虽然我知道我使用这段代码运行我的服务器它工作正常:

代码:

var http = require ("http");

http.createServer (function (request, response) {

    response.writeHead(200, {"Content-Type" : "text/plain"});
    response.write("Hellow world! I written my first server side code!"); //browser responding
    response.end();

} ).listen(8888);

但是当我尝试像这样导出服务器时,

var http = require("http");

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(8888);
    console.log("Server has started.");

}

exports.start = start; // the export module not work?

我在浏览器中收到错误:

Failed to load resource: Could not connect to the server.

我无法启动我的服务器,导出模块任何人都建议我修复此问题吗?

0 个答案:

没有答案