0

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

1
  • This code will send the same response to every request, no matter what the URL. You need to examine the URL of the request and serve up the correct file or, more realistically, use something like Express to handle routing requests and serving static assets (like CSS). Commented Mar 3, 2014 at 6:14

1 Answer 1

1

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

var connect = require('connect');    
connect.createServer(
    connect.static(__dirname)
).listen(8000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.