Skip to main content
D
Node.js
Node.js HTTP Module

Node.js HTTP Module

Node.js creates web servers that listen for requests.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

Node.js has a built-in HTTP module that transforms your computer into a live web server. The server listens on a specific port and sends text or HTML data back whenever a user tries to load the web page.

Example

Example
1/* this creates a server */
2var http = require('http');
3
4http.createServer(function (req, res) {
5  res.write('Welcome to my server!');
6  res.end();
7}).listen(8080);

Key Points

  • Import the module using `require('http')`.
  • The `createServer()` method builds the server.
  • The `listen()` method chooses the network port.
  • The server responds to incoming client requests.

Up Next

Continue your journey with the next topic.

Go to Node URL Module