DEV Community

Cover image for Day 14 – Serving HTML Pages - Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Day 14 – Serving HTML Pages - Learning Node JS In 30 Days [Mini series]

Do you know we can send html pages to the client?

Yes! You can do it using node js.

First we’ll create the server as like we created in day 12 tutorial

Alt Text

For sending the html file we need the fs module which in built in node.

Alt Text

I got the starter from bootstrap – https://getbootstrap.com/docs/4.4/getting-started/introduction/

Alt Text

We need to create stream using fs module. So that we can send the html file.

Alt Text

Then we can send it using pipe and send the response.

Alt Text

Now run it using node app.js

Alt Text

See the result

Alt Text

Let me know if you have any questions about it.

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

You can read the old posts from this series (below)

Latest comments (4)

Collapse
 
ojolanre_ profile image
The white wolf • Edited

When i run my localhost:3000 i get an this/an error on my console
dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
nerdjfpb profile image
Muhammad Ali (Nerdjfpb)

I think it's an issue with your location. Console log the index file location and see if that one is correct or not!

Collapse
 
ojolanre_ profile image
The white wolf

How can i do that, I'm just starting with NodeJS

Thread Thread
 
nerdjfpb profile image
Muhammad Ali (Nerdjfpb)

Can you share the files? DM me in twitter.