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

Node.js HTTP Module Basics

The Node.js HTTP module allows the creation of an HTTP server that listens to specified ports and responds to client requests. The createServer() method is used to create the server, while response.end() indicates the completion of the response. The server can handle different routes, providing specific responses based on the requested URL.

Uploaded by

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

Node.js HTTP Module Basics

The Node.js HTTP module allows the creation of an HTTP server that listens to specified ports and responds to client requests. The createServer() method is used to create the server, while response.end() indicates the completion of the response. The server can handle different routes, providing specific responses based on the requested URL.

Uploaded by

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

Node js HTTP module

 The HTTP module can create an HTTP


server that listens to server ports and
gives a response back to the client.
 Use the createServer() method to create
an HTTP server:
Node js HTTP module
var http=require('http');
var server = [Link](function(request,resp
onse)
{
[Link]('it is a request');
[Link]('Hello LPU');
[Link]();
})
[Link](2000);
createServer method
 createServer() method turns your
computer into an HTTP server.
 The http. createServer() method
creates an HTTP Server object.
 The HTTP Server object can listen to
ports on your computer and execute
a function, a requestListener, each time
a request is made.
[Link]() method
 This method signals to the server that all
of the response headers and body have
been sent; that server should consider
this message complete.
[Link]() method
 The server. listen() method creates a
listener on the specified port or path.
writeHead() method
 writeHead() method. This method sends
an HTTP status code and a collection of
response headers back to the client.
 The status code is used to indicate the
result of the request.
 For example, everyone has encountered a
404 error before, indicating that a page
could not be found.
Node js HTTP module
var http = require('http');
var server = [Link](function (req, res)
{
if ([Link] == '/')
{
[Link]('Welcome to Index page');
[Link]();

}
else if ([Link] == "/emp")
{
[Link]('Welcome to Employees page');
[Link]();

}
else if ([Link] == "/admin")
{
[Link]('Welcome to Admin page');
[Link]();

}
else
[Link]('Invalid Request!');
});

[Link](2020);

[Link]('Server is running at port 2020')

You might also like