To give you one wheel out of many:
function handler(req, res) {
switch(req.url) {
case '/':
case '/index.html':
.. send index.html here ..
break
case '/css/style.css':
.. send css/style.css here ..
break
default:
.. send 404 ..
break
}
}
On Mon, May 7, 2012 at 10:02 PM, Ryan Schmidt
<[email protected]> wrote:
>
> On May 7, 2012, at 13:59, Flexpadawan wrote:
>
>> Hi All,
>>
>> Newbie here so I'll do my best. I've spent the last two says trying to
>> figure out how to link my index.html page to my CSS file. There are a
>> couple of "Examples" out there but none of them worked for me, and of course
>> others have posted comments back as to why their approach is the wrong way
>> etc. So I have no idea what is the best practice is to order up a CSS
>> file....and get it to work! I do want to learn to do it the right way but I
>> need some guidance.
>>
>> Here is my starting file below. I guess my question is two part. 1) How do
>> I make my index.html page link to my CSS (css/style.css) file? 2) Should I
>> be using a pre-processor CSS engine like Stylus/Less?...and if so is there a
>> good example I can download and learn from? The posts out there don't seem
>> to be helping me at the moment.
>>
>> Environment:
>> Ubuntu Server 11.1
>> Node 0.6.15
>>
>>
>>
>> // Require Dependencies
>> var app = require('http').createServer(handler)
>> , fs = require('fs')
>> , io = require('socket.io').listen(app);
>>
>> // Server on ( localhost:8000 )
>> app.listen(8000);
>>
>> // Load up index.html page
>> function handler(req, res) {
>>
>> fs.readFile(__dirname + '/index.html', function(err, data) {
>> if(err) {
>> console.log(err);
>> res.writeHead(500);
>> return res.end('Error loading index.html');
>> }
>> else {
>> res.writeHead(200, { 'Content-Type': 'text/html' });
>> res.end(data, 'utf-8');
>> }
>> });
>> }
>
> Here, you've written an HTTP server that, for every request, regardless of
> the URL, returns the contents of the index.html file. Obviously not what you
> want.
>
> You may want to start by reading about expressjs, which makes it easy to make
> a web site using node. You could write it all yourself in node too of course
> and skip express, but why reinvent the wheel, especially when you haven't
> discovered the wheel yet? :)
>
> Whether or not you use stylus or less or similar is something you can decide
> for yourself. I think it makes sense to do so, but YMMV and for smaller
> projects it may not be worth the effort. It's probably simpler to start off
> without it; fewer things to learn all at once.
>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
Oliver Leics @ G+
https://plus.google.com/112912441146721682527
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en