title: How do you serve CSS in a node.js application
body: <p>I've been messing around with node.js and I can't seem to serve my CSS properly. Before, I had it embedded in my HTML in the header under a  tag, but now I'm trying to learn how to serve it as a separate file. </p>
  
  <p>So far, this is what I did. I tried to just write it in before adding loading the HTML under the server: </p>
  
  <pre><code>//This is all my main module
  
  var http = require('http');
  var router = require('./router.js');
  
  var server = http.createServer(function (request, response) {
  
  response.writeHead(200,{"Content-type" : "text/css"});
  var fileContents = fs.readFileSync('./views/styles.css', {encoding: "utf8"}, function(err, data) {
   if (!err) {
     response.write(data);
  } else {
    console.log(err);
  }
  });
  
    router.home(request, response);
    router.user(request, response);
  
  });
  
  server.listen(3000);
  </code></pre>
  
  <p>The home function that I called in the router module looks like this. It works perfectly fine too:</p>
  
  <pre><code>function home(request, response) {
    //if url == "/" &amp;&amp; GET
  
  if (request.url === "/"){
  if(request.method.toLowerCase() === "get") {
    response.writeHead(200, commonHeaders);
    renderer.view("header", {}, response);
    renderer.view("search", {}, response);
    renderer.view("footer", {}, response);
    response.end();
  
  } else {
      //if url == "/" &amp;&amp; POST
  //redirect to /:username
  
    request.on("data", function(postBody) {
      var query = querystring.parse(postBody.toString());
      response.writeHead(303, {"Location":"/" + query.username});
      response.end();
    });
    }
   }
  }
  </code></pre>
  
  <p>All of my HTML loads perfectly fine. If I use my dev tools in chrome, it shows that I've created a separate folder with a styles.css file in it, but it's empty. How come it's creating my file, but my CSS isn't being written in there?</p>
  
  <p>Am I doing this all wrong? I have a stylesheet linked in the header of my HTML as well. How do you serve CSS in a node.js application? I have no idea why this doesn't work.</p>