Find out how to serve an `index.html` HTML page using Node.js with no dependencies. I had the need to serve an HTML page from a Node.js server.
index.html
HTML page using Node.js with no dependenciesPublished Aug 16, 2020
I had the need to serve an HTML page from a Node.js server, and this is the simplest code that does the trick:
const http = require('http')
const fs = require('fs')
const server = http.createServer((req, res) => {
res.writeHead(200, { 'content-type': 'text/html' })
fs.createReadStream('index.html').pipe(res)
})
server.listen(process.env.PORT || 3000)
No dependencies needed.
Add this to an app.js
file, then create an index.html
page, and run node app.js
Notice that the above code does not provide support for serving static assets, it will just serve the index.html
page.
HTML Assignment Help Australia @30% OFF from Sample Assignment, with Our Best HTML assignment help experts. Get HTML homework help online at affordable price. 100% Plag free assignment solution.
HTML tags are keywords used in HTML to display web-pages with certain properties. They are further used for defining HTML elements. An HTML element consists of a starting tag.
HTML is the mark-up language most websites are written in. In this article, we will delve into the most basics of HTML like tags and elements that are of utmost importance while writing any code in HTML. These tags help in the structuring and display of content on the web pages.
Learn about HTML Button & various effects on these buttons like ripple, fade-in & pressed. Learn types of HTML buttons - shaded button, animated button etc.
Coming as a beginner into HTML can be difficult, especially for the amount of default properties and behaviors that are in place and nobody tells you about it. In this article, I am going to show you how these things work, how you can modify their default behavior, and help you get a better understanding of HTML that will be useful any time there is a roadblock in the rendering of your page.