I have the following code on my node.js server (I'm using express):
app.get('/appointment/:id',function(req,res){
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<link href="public/css/style.css" rel="stylesheet" type="text/css">');
res.write('<form name="accept" action="http://localhost:8080/appointment/'+ req.params.id+'/1" method="post">');
res.write('<input id="accept" type="submit" value="Accept">');
res.write('</form><br>');
res.write('<form name="decline" action="http://localhost:8080/appointment/'+ req.params.id+'/0" method="post">');
res.write('<input id="decline" type="submit" value="Decline">');
res.write('</form><br>');
res.end();
});
In my root folder I have folder appointment/public/css/style.css.
When I open the web page it just displays 2 form buttons but without CSS applied.
The CSS code is:
#accept {
width:50px;
height:30px;
background-color:#00FF00;
color:#FFFFFF;
font-weight:bold;
font-size:120%;
}
#decline {
width:50px;
height:30px;
background-color:#FF0000;
color:#FFFFFF;
font-weight:bold;
font-size:120%;
}
What is the problem and how can I fix it?
EDIT: The hierarchy is as follows:
-server_files
--nodeServer.js
--public
---css
----style.css
app.use(express.static(__dirname + '/public'));, and add/beforepublic/css/style.css/publicis your static root directory, thenhttp://localhost/foo.cssmaps to the filepublic/foo.css. (The name of the static root directory never appears in static HTTP paths; the filesystem'spublicbecomes the server's/(the root)) You need to use/css/style.cssin your<link>.