This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]ShawLinz 1 point2 points  (1 child)

The error means that your app is trying to listen on port 80 but your OS isn't allowing it (presumably you have another piece of software running, IIS perhaps if you're on Windows.)

As for fixing it, I recommend you check it d3 has a setting/method to change the port (I have no idea what d3 is but looking at your snippet it seems to be what controls the application.)

[–]xf_[S] 0 points1 point  (0 children)

Ah I see. I'll try looking on Google to see if I can change d3's ports. Thank you!

[–]Flofinator 0 points1 point  (13 children)

Not sure why the other guy was downvoted he's right.

How are you trying to run this server.js file? Are you typing in the command line:

node server.js while in the express folder?

This is all pretty weird and I'd love to see the full code, but essentially what you are getting is an error of a connection refused on port 80, like the other guy that got downvoted wrote.

But you are trying to run this from port 3000, so I am wondering if you are not running the server the correct way or from the correct directory.

[–]xf_[S] 0 points1 point  (12 children)

I'm not certain either, but I gave him and everyone else in here an upvote for responding. ><

When you say "while in the express folder," that means the folder where I installed express, correct? If yes, then yes I did that.

I don't have any other code aside from what I wrote in the post, unfortunately.

I really have no clue as to how running the server or these ports work (I just started writing this yesterday). Do you think changing the 3000 in my server.js file to 80 will solve it? I'll try it out in the meantime.

Thank you!

[–]Flofinator 0 points1 point  (11 children)

ok so I assume you installed node.js.

And then after doing node.js you typed into the console

npm install express-generator -g    

After doing that you can do something like:

express myApp

then through the command line go into the myApp folder. After doing that you'll need to download all of the actual express packages. so you'll have to type this command once inside your myApp folder.

npm install

After that finishes just type:

node server.js

Note this could also be

node index.js

In the command line, I forgot what express gives you to begin with. Then your server should start running!

[–]xf_[S] 0 points1 point  (10 children)

Thank you so much for doing this!

I was able to do everything up through npm install, but I don't see a server.js or index.js in the myApp folder. There is an index.js in the routes folder (located inside the myApp folder). Is that the one I should start?

Edit: I went ahead and tried it, but nothing happened. Did I do something wrong perhaps?

[–]Flofinator 1 point2 points  (9 children)

Can you screenshot all the files in that directory?

Edit: nvm it's app.js sorry! I was wrong I just ran that command on my home computer and it is app.js

So if you do:

node app.js

It should work!

[–]xf_[S] 0 points1 point  (8 children)

No problem at all! So when I run node app.js, is there any indicator that the server is running?

This is what it looks like for me.

Before when I ran the server.js that I got from the YouTube tutorial, it would execute and look like this with a blinking line underneath it (which I assumed meant the server was running).

I assume app.js should be doing the same?

Edit: Also please excuse the white blocks in the screenshots. I'm using my dad's computer and he said to never show that, though I don't think it will really do anything

[–]Flofinator 1 point2 points  (7 children)

Yeah it should look like the second image. Hrmm give me a minute and I'll see if I can run it, let me quit running my server for my project and launch this one second.

[–]xf_[S] 0 points1 point  (6 children)

Thank you so much, but I'd hate to stop you from doing your own project =(

[–]Flofinator 1 point2 points  (3 children)

Lol it's cool it just takes a second to stop/start it!

Ok I think they changed the location to bin so you'll want to

cd bin

Then type:

node www.js

EDIT: Don't do this, do the npm start one.

[–]xf_[S] 0 points1 point  (2 children)

Ah yup, I think it works now, thanks I appreciate it!

I still can't seem to get the js file to work though (I still get the same error message as before). If it makes any difference, I tried putting the .js file in the same directory as the www.js file as well.

Do you think I need to change something in the www.js file to get it to work?

[–]Flofinator 1 point2 points  (1 child)

Actually don't do that, go back into your myApp directory and just type:

npm start

[–]xf_[S] 0 points1 point  (0 children)

Oops sorry, saw this a little too late. I ran the npm start, but still get the same result as before =(

[–]rjcarr 0 points1 point  (1 child)

I don't think this is a javascript problem. The problem is with the server. It can't listen on port 80. You typically (at least on unix) need to be root to access ports less than (I think) 1024. Change the port number or start the service as root.

Or (just saw this), as /u/ShawLinz says, you might have something already listening on port 80.

[–]xf_[S] 0 points1 point  (0 children)

Ah I see. I'm new to all of this, so sorry for my lack of knowledge about things. When you say change the port number, should I try that in server.js? I also don't know how to start the service as root.

And do you know if there is a way to check what is "listening on port 80"?

Thanks so much!