I'm trying to learn nodejs. I want to serve a static html file using mustache and nodejs. I create a module for start the server with this code :
var http = require("http");
function startServer(){
function onRequest(request,response){
console.log("Request received");
response.writeHead(200, {"Content-type" : "text/html" });
response.write("hello");
response.end();
}
console.log("The server is running at http://localhost:8888");
http.createServer(onRequest).listen(8888);
}
exports.startServer = startServer;
and then I do this on the indexjs file :
var server = require("./server");
var util = require("util");
var fs= require("fs");
var mu = require("mu2");
function renderIndex(){
var streamIndex = mu.compileAndRender('index.html',{"name" : "Antonio"});
util.pimp(streamIndex, response);
}
server.startServer(renderIndex);
I know that I'm doing something completely wrong, but can't get where is the error. I tried to merge 2 different tutorials i was reading about nodejs.
P.S: I know that i could use express or other frameworks, but i would like to start using nodejs from scratch to understand how it really works.