Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js HTTP Methods and Headers Sending Content Type Headers in Node.js

Carlos Lantigua
Carlos Lantigua
5,938 Points

Adding css to a separate file

Trying to put css in a separate file for the node.js treehouse API project and I am not able to using conventional methods. If I make a seperate file named "css.styles" would I have to write it in the node file as

renderer.view("styles", {}, response);

or would I have to use something else?

1 Answer

Erika Suzuki
Erika Suzuki
20,299 Points

If the website is deployed live, you have to either serve the static assets (css, js, images, fonts) from a web server (nginx, apache, etc.) or use a readily available Javascript module to serve assets programmatically.

Or if you're up for some challenge, you can make it yourself by making a router for static assets, dynamically determine content-type and then pass it to the response.

Erika Suzuki
Erika Suzuki
20,299 Points

Anyway, let's stay tuned, may be it'll be taught to us here in this course. :)

Carlos Lantigua
Carlos Lantigua
5,938 Points

Thank you for the reply, I'm sorry I haven't been on treehouse in a while because I'm working on coding projects.

Erika Suzuki
Erika Suzuki
20,299 Points

Carlos Lantigua sure! Anyway, having done the rest of the course. There is a way using Express JS! It's incredibly easy.

can we do all this stuff more easily on express?