如何在Node.Js中设置默认主页?

时间:2014-03-24 09:37:07

标签: node.js

这是我的代码我能够看到这个文件内容但是在刷新时,不是我输入本地主机和端口。

// Include http module,
var http = require("http"),
// And url module, which is very helpful in parsing request parameters.
    url = require("url");
 var EventEmitter = require('events').EventEmitter;
 var fs = require('fs');
 var emitter = new EventEmitter;
var fdata="";
http.createServer(function (request, response) {

if(request.url=="/")
{
        response.writeHead(200, {'Content-Type': 'text/html'});
      fs.readFile("xhtmlJs.xhtml","UTF-8" ,function (err, data){
           fdata=data;       
    });
    response.write(fdata+"<br/>"+request.url);
     response.end();
 }
}).listen(1234);

0 个答案:

没有答案