Serve an HTML page using Node.js

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, 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)