

Server.listen(7000) Handling GET Requests in Node.js Var server=http.createServer((function(request,response) Here is the code for your reference var http=require('http') Because in our code we have mentioned specifically for the server to listen on port no 7000, we are able to view the output when browsing to this url.You can clearly see that if we browse to the URL of localhost on port 7000, you will see the string ‘Hello World’ displayed in the page.If the command is executed successfully, the following Output will be shown when you run your code in the browser.

You can specify any available port over here. We are then using the server.listen function to make our server application listen to client requests on port no 7000.In the response itself, we are sending the string ‘Hello World.’.When a request is received, we are saying to send a response with a header type of ‘200.’ This number is the normal response which is sent in an http header when a successful response is sent to the client.This function is called whenever a request is made to our server application. In this line of code, we are creating a server application which is based on a simple function.So in our case, since we want to use the functionality of the http module, we use the require function to get the desired functions from the http module so that it can be used in our application. The basic functionality of the require function is that it reads a JavaScript file, executes the file, and then proceeds to return the exports object.If a request is made through the browser on this port no, then server application will send a ‘Hello World’ response to the client. Our application is going to create a simple server module which will listen on port no 7000. Let’s look at an example of how to create and run our first Node js application. We will have a look at how we can create a basic web server application using Node js. There are a variety of modules such as the “http” and “request” module, which helps in processing server related requests in the webserver space. The framework can easily be used to create web servers which can serve content to users. The Node.js framework is mostly used to create server-based applications.
