learnyounode
learnyounode copied to clipboard
Can't verify http file server
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.
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?
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 .