Wednesday, August 7, 2013

How set start page in nodejs

How set start page in nodejs

I use node js without frameworks etc. and I have problem, I don't
understand how set "start html page" for my first request to server.
I tried do it like this
var server = new http.Server();
server.listen(1137, '127.0.0.1');
server.on('request', function(req, res) {
fs.readFile('../public/index.html', function (err, html) {
if (err) {
throw err;
} else {
res.write(html);
res.end();
}
});
});
When I do request to 127.0.0.1:1137 - I got html in browser, but links to
CSS/JS files isn't correct and how I can this to fix I don't know :(
I want get the html page ../public/index.html in browser when I will do
first request to my server.
my server location project/server/server.js
my html-page location project/public/index.html

No comments:

Post a Comment