Reputation: 523
So in node.js I render the html page which is included in view/index.html. I also included a css stylesheet in the head tags, but it's not rendering. Is there anything I should know about how this should be formatted in the file system: for example, does there have to be a style folder or something for the css to be in?
Thanks.
Upvotes: 2
Views: 5306
Reputation: 7124
What are you using to serve the page at view/index.html? Are you simply using fs to read in the file and then sending the contents of the file in response to the request? Or are you using a middleware framework like Connect or Express? Can you provide a link to the site that you are working on, and the relevant extracts of your JavaScript code?
Upvotes: 0
Reputation: 5480
You will need an endpoint that serves the CSS file, or use a static directory. If you are using Express, the following code when configuring the app will set a directory which will be served statically.
app.use(express.static(path.join(__dirname, 'public')));
This will tell Express to serve everything in the '/public' directory as static content.
If you are not using Express, you can take a look at this question, Node.js static file server logic (using Connect middleware), which should help you.
Upvotes: 5
Reputation: 146164
You need to write code to actual respond to the HTTP GET request the browser will issue for the stylesheet and send back the CSS data. Basically however you are serving view/index.html
it will be similar but with a different URL, different content-type header, and different static file to send in the response. You posted no code, so you get English instead of JavaScript.
Upvotes: 0