首页 > 代码库 > nodeJS使用——示例1

nodeJS使用——示例1

 

//console.log("hello world");var http=require("http");var server=http.createServer(function(request,response){    console.log(request.method);    console.log(request.url);        if(request.method==="GET"){       response.setHeader("Content-Type","text/html");       response.setHeader("Content-Encoding","UTF8");//UTF8编码       var html="";//html代码       switch(request.url){            case "/":            case "/index.html":                html="<html><head><meta charset=‘UTF8‘/>"+  //UTF8编码                        "<title>标题</title></head><body>"+                        "<h1>欢迎来到XX网</h1><br/>"+                        "<a href=http://www.mamicode.com/‘/add.html‘>ADD
"+ "<a href=http://www.mamicode.com/‘/remove.html‘>REMOVE
"+ "<a href=http://www.mamicode.com/‘/find.html‘>FIND
"+ "<a href=http://www.mamicode.com/‘/edit.html‘>EDIT
"+ "</body></html>" ; break; case "/add.html": html="<html><head><meta charset=‘UTF8‘/>"+ //UTF8编码 "<title>标题</title></head><body>"+ "<h1>欢迎来到XX网</h1><br/>"+ "ADD UI界面..."+ "</body></html>" ; break; case "/remove.html": html="<html><head><meta charset=‘UTF8‘/>"+ //UTF8编码 "<title>标题</title></head><body>"+ "<h1>欢迎来到XX网</h1><br/>"+ "REMOVE..."+ "</body></html>" ; break; case "/find.html": html="<html><head><meta charset=‘UTF8‘/>"+ //UTF8编码 "<title>标题</title></head><body>"+ "<h1>欢迎来到XX网</h1><br/>"+ "FIND UI界面..."+ "</body></html>" ; break; case "/edit.html": html="<html><head><meta charset=‘UTF8‘/>"+ //UTF8编码 "<title>标题</title></head><body>"+ "<h1>欢迎来到XX网</h1><br/>"+ "EDIT UI界面..."+ "</body></html>" ; break; default : html="<html><head><meta charset=‘UTF8‘/>"+ //UTF8编码 "<title>标题</title></head><body>"+ "<h1>404</h1><br/>"+ "REQUEST URL NOT FOUND..."+ "</body></html>" ; console.log("Invalid request URL:"+request.url); }; response.end(html); } response.end();});server.listen(80);

 

nodeJS使用——示例1