workshopper / learnyounode

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
Other
7.25k stars 1.84k forks source link

HTTP File Server convention Q's #499

Closed Chrinkus closed 6 years ago

Chrinkus commented 7 years ago

I was able to complete exercise 11 with the following code:

var http = require("http"),
    fs = require("fs"),
    server, readable;

readable = fs.createReadStream(process.argv[3]);

server = http.createServer(function(req, res) {

    readable.pipe(res);
});

server.listen(process.argv[2]);

Though the above "passed" there was a red "x" and a note "Used fs method other than fs.createReadStream(): fs.createReadStream()". Is it recommended to create a new read stream object every request?

Also, the solution contained the line:

res.writeHead(200, { 'content-type': "text/plain" });

What does this line actually accomplish?

MeloGuo commented 6 years ago

You should to search the Node.js API:

response.writeHead

If you don't understand it. You should to learn some knowledge of HTTP.

Chrinkus commented 6 years ago

@Mluka yes, thank you. I attempted many node school workshoppers before my knowledge of what I was actually doing was ready. I'm good now!