HTTP and Networking: Serve an HTML page using Node.js

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


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.

Lessons in this unit:

0: Introduction
1: Run a web server from any folder
2: HTTP requests in Node using Axios
3: Make an HTTP POST request using Node
4: Making HTTP requests with Node
5: Get HTTP request body data using Node
6: ▶︎ Serve an HTML page using Node.js
7: Using WebSockets with Node.js