learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

Can't verify http file server

Open sabian2008 opened this issue 9 years ago • 2 comments

Hi! I can't verify program.js for the HTTP FILE SERVER exercise.

This is the code which I've written:

var http = require("http");
var fs = require("fs");

var port = process.argv[2];
var filename = process.argv[3];

var server = http.createServer(function (req, res) {
    var file = fs.createReadStream(filename);
    file.pipe(res);
});
server.listen(8000); 

However if I run both

 nodejs program.js 8000 file

and then

curl localhost:8000

it works as expected.

I've tried running verify several times, and for several minutes. However Terminal Emulator gets stuck waiting for command to exit and must interrupt it.

sabian2008 avatar Dec 30 '15 22:12 sabian2008

Solved. I was passing 8000 for port listening instead of appropriate argv. Silly me.

However I think that some error-checking in verify is failing, right?

sabian2008 avatar Dec 30 '15 23:12 sabian2008

Thanks for the post . I found out the mistake I was doing :)

file.pipe(res); // I am passing the file argument again to the pipe .

ghost avatar Jan 18 '16 06:01 ghost