Jump to content

Node.js CSS3 not working

Recommended Posts

I am attempting to learn Node.js, I hope someone here knows it.

var express=require('express');
var app=express();
var port=process.env.PORT||3000;

app.use('/assets', express.static(__dirname+'/public'));

I require express and next line create and instantiate a var app then next line I do the same for var port


last line I 'believe' I am causing express to look in my public file when I use the var assets in a line of code later, will show line

			+'<link href=assets/style.css type=text/css rel=stylesheet/>'
			+'<title> 9/3 </title></head><body><h1>Hello World!</h1><h2>'
			+'Using Express to make my life easier</hr></body></html>');

Here I am creating a HTML page for localhost:3000 , because 3000 is the default port as shown above. Everything works save the following line

+'<link href=assets/style.css type=text/css rel=stylesheet/>'

I cannot get the css3 to work yet I 'believe' the link is correct, the word assets in the link tag should be dynamically changed to public causing the NODE.JS server to use the style.css file IE /public/style.css


I see no style change at all and when I look at the source code this is the line printed

<link href="/assest/style.css" rel="stylesheet" type="text/css" >

I do not know but I thought it would be localhost:3000/public/style.css below is the CSS

body{color: red;}

which as I said is ni the public folder which is in the same folder as the app.js holding the code in question


What am I doing wrong that will not use the CSS?



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...