title: node.js sending css files
body: <p>I'm trying to get a node.js server to send css files. I'm modifying this server here:</p>
  
  <p><a href="http://github.com/LearnBoost/Socket.IO-node/blob/master/test/server.js" rel="nofollow noreferrer">http://github.com/LearnBoost/Socket.IO-node/blob/master/test/server.js</a></p>
  
  <p>What's wrong with what I'm doing:</p>
  
  <pre><code>server = http.createServer(function(req, res){
      // your normal server code
      var path = url.parse(req.url).pathname;
      switch (path){
          case '/':
              res.writeHead(200, {'Content-Type': 'text/html'});
              res.write('&lt;h1&gt;Welcome. Try the &lt;a href="/chat.html"&gt;chat&lt;/a&gt; example.&lt;/h1&gt;');
              res.end();
              break;
  
          default:
              if (/\.(js|html|swf)$/.test(path)){
                  try {
                      var swf = path.substr(-4) === '.swf';
                      res.writeHead(200, {'Content-Type': swf ? 'application/x-shockwave-flash' : ('text/' + (path.substr(-3) === '.js' ? 'javascript' : 'html'))});
                      res.write(fs.readFileSync(__dirname + path, swf ? 'binary' : 'utf8'), swf ? 'binary' : 'utf8');
                      res.end();
                  } catch(e){ 
                      send404(res); 
                  }               
                  break;
              }
              else if (/\.(css)$/.test(path)){
                      res.writeHead(200, {'Content-Type': 'text/css'});
                      res.end();
                      break;
              }
  
              send404(res);
              break;
      }
  });
  </code></pre>
  
  <p>Thanks.</p>