workshopper / learnyounode

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

Unable to complete HTTP-server lesson #224

Open TransGirlCodes opened 9 years ago

TransGirlCodes commented 9 years ago

Hi,

I've written the following answer to the exercise:

var http = require('http');

http.get(process.argv[2], function callback (response) {
            response.setEncoding('utf8');
        response.on("data", function (data) {
            console.log(data);
        });
});

But when trying to run it with learnyounode run http.js I get:

Bens-MacBook-Pro:~ axolotlfan9250$ learnyounode run http.js /Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/exercises/http_client/exercise.js:52 this.server.close(callback) ^ TypeError: Cannot read property 'close' of undefined at Exercise. (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/exercises/http_client/exercise.js:52:14) at next (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:260:17) at Exercise.end (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:266:5) at Workshopper.end (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper/workshopper.js:197:12) at Workshopper.done (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper/workshopper.js:329:19) at Exercise. (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:149:14) at /Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:136:16 at Exercise. (/Users/axolotlfan9250/.nvm/v0.11.14/lib/node_modules/learnyounode/node_modules/workshopper-exercise/filecheck.js:10:14) at Object.oncomplete (fs.js:93:15)

So I looked up the official solution, which includes waiting for an error event:


var http = require('http');

http.get(process.argv[2], function callback (response) {
        response.setEncoding('utf8');
        response.on("data", function (data) {
            console.log(data);
        });
        response.on('error', function(error) {
            console.log(error);
        });
});

But this still does not help, the same output is returned. What is going wrong?

Thanks, Ben.

rvagg commented 9 years ago

There's multiple things going on here. There's some kind of problem unrelated to the solution you're using but it's being masked by another problem in learnyounode which I've proposed a fix for in #225. Basically something is failing during setup and it's jumping straight to cleanup but the cleanup is what's throwing that error. The actual problem could be something like not being able to listen on a specific port, or something even stranger.

So, you can wait till #225 gets merged if you want or persevere and see if you can figure out what's wrong on your system. I'd suggest starting with getting off Node 0.11.14, it's not supported or recommended. Either go back to 0.10.36, go up to 0.12.0 or switch to io.js.