Create a file server using Node.js with the following attributes.
It listens for GET requests and sends back files.
It listens on the port specified in the command to start the server. The following command sets the port to 3004.
node index.js 3004
It responds with status code 200 when it finds and sends back a file.
It responds with "Sorry we couldn't find your page!" and status code 404 when it doesn't find a file.
Put your Project 1: Video Poker files in the file server folder. Try to access your video poker project at localhost:3004
We use content type headers in HTTP responses to communicate to the client the type of data in the response content. We will update our file server to incorporate this. Reference this example for how to use content type response headers, and read more about content type headers here.
The content type example above uses require statements, which will not work in the environment in which we are running Node. Use import statements instead.
Update our file server with the following features.
It only sends a file back when it can detect the file type of the requested file (e.g. by file extension).
It sets the correct content type in the header of the response.
It sends back an HTML 404 page when it can't find the requested file.
Create an "easter egg" so that whenever a user visits /banana they get the response "hello banana!".
On every response create an easter egg header of 'rocket-academy-secret-word' in the response. Set the value to 'blastoff'.
Click here to see the reference solution for this post class.