Red de conocimiento informático - Material del sitio web - ¿Cómo abrir archivos HTML en un proyecto usando nodejs?

¿Cómo abrir archivos HTML en un proyecto usando nodejs?

var http = requerir("http"),

url = requerir("url"),

ruta = requerir("ruta"),

fs = require("fs");

http.createServer( function (req, res) {

var nombre_ruta=__dirname+url.parse(req.url).nombre_ruta;

if (ruta.extname(rutanombre)=="") {

rutanombre+= "/";

}

if ( nombre_ruta.charAt(nombre_ruta.length-1)=="/"){

nombre_ruta+="index.html";

}

ruta.existe (nombre de ruta, función (existe){

if(existe){

switch(ruta.extname(nombre de ruta)){

caso ".html":

res.writeHead(200, {"Content- Type": "text/html"});

break;

case ".js":

res.writeHead(200, {"Content-Type": "text/javascript"});

break;

case ".css":

res.writeHead(200, {"Content-Type": "text/javascript"});

break;