0% found this document useful (0 votes)
5 views3 pages

Understanding NodeJS HTTP Module Basics

Uploaded by

sushree007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Understanding NodeJS HTTP Module Basics

Uploaded by

sushree007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lesson:

Http Module
List of content:
What is http
NodeJS http module

What is http ?

HTTP stands for Hypertext Transfer Protocol. It is a protocol used for transmitting data over the internet. HTTP
defines how clients and servers communicate with each other and how requests and responses should be
formatted and transmitted. It is the foundation of data communication for the World Wide Web or the internet.

NodeJS http module

Node's http module is an integral component that facilitates various aspects of the HTTP protocol. To use the
http module, start by creating a new file named "[Link]" and then import the http module using the require()
function, as demonstrated in the following example:

Second, create an HTTP server using the createServer() method of the http object.

When utilizing the createServer() function, a callback function with two parameters - HTTP request (req) and
response (res) - is required. If the URL is "/", an HTML string is sent to the browser and the request is terminated
within the callback function.

Full Stack Web Development


Finally, the incoming HTTP request is monitored on port 5000.

Lets put it all together:

Output:

Now, you can launch the web browser and go to the URL [Link] You’ll see the following
message:

This simple example illustrates how to use the http module. In practice, you will not use the http module directly.
Instead, you will use a popular module called express to handle HTTP requests and responses.

Full Stack Web Development

You might also like