Outline

A common need in JavaScript is to have a server that listens for and responds to HTTP requests. Deno has a module that will help you to do that. You can view the documentation here. This module allows you to specify a port for the server to run on, and then will respond to those requests.

In the assignment for this section, you will create a simple HTTP server that listens for requests and responds. The port the server runs on should be designated with a flag, --port. Make sure to have a default value for the flag. Only respond with a successful message to GET requests, but all other requests should return an error.

Line 8 at the end of the example gets cut off, but here it is:

req.respond({ body: JSON.stringify({ message: 'Hello there!', count: ++requestsRespondedTo }) });

Hint: To do this, you will need to check the request.method attribute.

 

I finished! On to the next chapter