Amila Iddamalgoda
Amila Iddamalgoda

Reputation: 4286

Node js + load html and css files in a folder

I'm developing a node js project here is my project hierarchy.

enter image description here

Here is my .njs file

    var http = require('http'),
    fs = require('fs');


fs.readFile('./home.html', function (err, html) {
    if (err) {
        throw err; 
    }       
    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    }).listen(8000);
});

But css files are not loaded.Please help me out with the correct coding.Thnx

Upvotes: 0

Views: 347

Answers (1)

ioseph
ioseph

Reputation: 1917

I found the 'connect' module very simple to use:

var connect = require('connect');    
connect.createServer(
    connect.static(__dirname)
).listen(8000);

Upvotes: 1

Related Questions