Node.js assignment problem with server on Cloud9 [Solved]

I’m working on the Node challenges and everything was working fine until now. Now every time I try to run anything in the run configuration I get this throw error.

I’ve searched far and wide and the general consensus is that this means I have two processes attempting to run on the same port at the same time and that I need to shut down anything that is also running.

I have no clue how to do that. This line seems like it’s trying to tell me what to do:

Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

How do I do that?

Your code is running at https://learnyounode-nicknyr.c9users.io.
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

Debugger listening on port 15454
events.js:141
throw er; // Unhandled ‘error’ event
^

Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)

Can you post your code so I can see what you have so far?

//process.argv[2]

var bl = require(‘bl’);
var hyperquest = require(‘hyperquest’);
var url = ‘process.argv[2]’;
var http = require(‘http’);
var response = require(‘response’);
var http = require(‘http’);

http.get(process.argv[2], function (request) {
response.pipe(bl(function (err, data){
if(err){
console.error(err);
}
console.log(bl.length);
console.log(bl.toString());
}))
})

Here’s my code (which I know most likely isn’t correct) but it doesn’t matter what I try to run. I always get the throw error.

Which Learnyounode lesson is this for? It was a while ago since I did it, so I’m trying to remind myself what it was asking for.

HTTP COLLECT (Exercise 8 of 13)

Write a program that performs an HTTP GET request to a URL provided to you
as the first command-line argument. Collect all data from the server (not
just the first “data” event) and then write two lines to the console
(stdout).

The first line you write should just be an integer representing the number
of characters received from the server. The second line should contain the
complete String of characters sent by the server.

since you are using “request” as the parameter in your function, you need to use that in your body instead of response.

i…e instead of

http.get(process.argv[2], function (request) {
response.pipe(bl(function (err, data){

you need -

request.pipe(bl(function (err, data){

Also, I don’t understand why you require “response” i.e.
var response = require(“response”) as you’re not doing anything with it.

Heh! While I was of solving the challenge again to remind myself, @jaytsecan just read your code carefully! There’s a lesson in that for me!

Edit
Actually, that doesn’t fix the error you’re getting. I can pass the challenge without using bl, so that may be the issue…

Ok, got it.

You have two bugs and a couple of style issues.

To fix your current bug, you need a space between ‘if(err)’ like this: if (err)

You will then find that passing ‘bl’ in your console.logs causes problems. You want to pass the data object, not call the bl function again…

Stylewise, as @jaytsecan pointed out, you have some modules you are requiring, but not using, such as ‘response’ and ‘hyperquest’. You also include http twice. Finally, you set the url variable, but you never use it.

It’s still not working. Still get the throw error.

I don’t understand what’s wrong with my error handling.

This is what I have now:

var bl = require(‘bl’);
var http = require(‘http’);

http.get(process.argv[2], function (request) {
request.pipe(bl(function (err, data){
if (err){
console.error(err);
}

    console.log("Hello world");
    //console.log(data.length);
    //console.log(data.toString());
}))

})

I commented out the console.log()'s and just replaced them with a simple hello world just to see if I’d get the throw error still, and I did.

Are you sure? I just copy and pasted your exact code in to cloud9 and it worked…

Yeah this is what I’m getting. Like I said, I think it’s an issue with Cloud 9 trying to use the same port that I have something else running on. I don’t have anything else open though.

The other night I was messing around on the terminal trying to play with Heroku. Is it possible I still have a server running in the background?

Hmmm…not sure about this.

I’m running it on c9 as well, but the error messages I got were different. I didn’t get the ‘debugger listening…’ bit, or the report that my code was running at https://learnyou blah blah

How are you running your learnyounode programs?

Oh…hang on - you’re using the ‘Run’ button. I get the same error when I use that.

You can (and should) run all the ‘learnyou’ modules through the terminal directly.

In the terminal window type learnyounode run program.js (where program.js is the name of your program file).

To pass the tests type learnyounode verify program.js.

That should work.

That worked!

I’m thinking maybe I had that issue with the ports because I had the server running in the terminal and I was trying to run the program with the play button. That’s my guess.

I was going nuts over this. Thanks for the help guys.

This seems more like a Cloud9 quirk than a Node issue.

I think the run button assumes you want to run node program.js rather than learnyounode run program.js, or it might try to start a server it assumes you’ve set up and run any appropriate file linked to that. I’m not sure.

But because the learnyou modules fake some of the actions you need to do, I think everything runs through its own tutorial environment that c9 doesn’t know how to deal with.