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