shireen-bean / node-http-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General Assembly Logo

Node HTTP Module: Server

Node has a built-in HTTP module for making and responding to requests. In this training, we'll examine the Node HTTP docs and annotate server code. We'll become familiar with the HTTP module, as well as using function signatures to find the correct documentation for a procedure. We'll also look at a promisified version of a simple server.

Prerequisites

Objectives

By the end of this, developers should be able to:

  • Diagram the flow of a server written in Node.
  • Annotate code using documentation.
  • Find documentation based on function signature.

Preparation

  1. Fork and clone this repository.
  2. Install dependencies with npm install.

Lab: Read Node Server Documentation

Read the following documentation from the Node HTTP module. While reading, take note of any new concepts or vocabulary that is confusing. Pay attention to function signatures. When you're finished taking notes, research one or two points you'd like made clearer. We will discuss our findings.

Demo: A Node Echo Server

An echo server is a server that responds with all the information it received during a request. It's a bit like "Hello, World!".

Let's run the echo server with node lib/htpp-server.js. You should see echo server listening. Now make a request with curl:

curl --include --request GET \
  http://localhost:3000/people/?name=Jason&role=Awesome

Next, try this request:

curl --include --request POST http://localhost:3000/sign-in \
  --header "Content-Type: application/json" \
  --data "{
    \"credentials\": {
      \"email\": \"an@example.email\",
      \"password\": \"an example password\"
    }
  }"

Annotate Along: Echo Server

Let's read the code in lib/http-server.js. Our goal is to annotate the code as we try to understand what it is doing at a high level. As we take notes, write questions you have along with your notes.

After we annotate a few lines together, you may continue annotating on your own.

Read-Along: Examine a Promisified Server

Read the code in lib/http-server-promises.js. Compare it to the code in lib/http-server.js. Annotate any questions you have about promises.

Additional Resources

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.

About

License:Other


Languages

Language:JavaScript 100.0%