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
Bernd Plontsch
1,617 PointsServe image assets and page HTML in node.js
I followed the course "Build a Simple Dynamic Site with Node.js" to create a tiny http server and routes for serving dynamic HTML pages. Great.
I'd like to build on that and serve some images from a subfolder that are displayed within the served pages.
My understanding is that I need to extend the
http.createServer(function (request, response) { router.home(request, response); }).listen(3000);
⦠to include a way to serve images with their own content types (image/png). My problem with this so far (by adding a condition depending on the request path) was that I was either serving an image or a page without any images but not both at the same time.
Any hints what the best way to serve images assets for a page template? (ideally without using any npm packages).