Creating a Server

Jun's Coding Journey·2022년 10월 29일
0

[Challenge] Youtube Clone

목록 보기
4/19

In order to create a server, we need to make sure that we have express installed in our npm and import it to our JavaScript file. Just by importing, JavaScript can easily bring the designated module from the npm folder directly without the need for us to search it manually.

After importing, we then need to create a variable to initialize the express functionality. Just like this, we can create a server.

GET Request

In order to make the server listen to our request, we need to specify a port number and the actual request we want to send. We use the app.listen function to send our request (which also comes from a separate function) to the server.

Users interact with the browser server through the HTTP address which acts as a bridge for us users requesting a website to the server. When we input an address on the browser, the browser makes the request to the server. If the address exists the server will bring the requested address to the browser screen.

GET Response

After sending a request, we also need to make sure the server responds to that request. We use the app.get function to get the specified address on the browser. We then create a function that will respond to our request which will send a response to the request. Typically, we use the res.send function to respond to specified requests which the server will read and respond to.

profile
Greatness From Small Beginnings

0개의 댓글