简体   繁体   中英

Node.js “Server listening on port 3000”, but I can't view it in browser?

I am trying to get a simple node app running. It works fine on my localhost, but as soon as I am trying to get it to run on my cloud server, it doesn't work. When I do "node app.js" in the right path I get my console.log Express server started on port %s', server.address().port and it also says that it is port 3000(Express server started on port 3000). When I change the server.listen to another port, it displays the right port.

Now when I try to get it running via my domain or via my ip(for example xx.xxx.xx.xx:3000) or my domain (my-domain.com:3000) in both cases it doesn't work. I think I don't quite get the concept and I tried to search for a billion different things, but I can't find the solution to my problem. Could someone tell me, if I need to setup something else, too?

It's likely that your code is working but that your server is not configured to allow access to port 3000.

To confirm You could try changing your app to Port 80 which is a default and most likely enabled.

Search your host documentation for 'enabling or opening ports'

Propably your cloud hosting provider doesn't have the port open for access. Try port 80 which is usually open.

I faced the same issue. After banging my head a lot, checking all opened/used ports and trying various other stuff, I finally found out that since I was using AWS, I had to actually enable that port through Security Group section for my AWS EC2 instance.

I had to add a Custom TCP Rule in Security Group section for port number 3000 which I wanted to use for NodeJS server after which NodeJS server started responding on port 3000.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM