Express server unreachable from browser when running in WSL2 - node.js

So, I have been trying to start a basic express server from inside WSL2 on port 3000. Every time I go to the browser, it says that "localhost:3000" is unreachable. I'm not really sure where the problem is. I have been able to start and access react applications that are running on port 3000 in WSL2 without a problem. Additionally, I have been able to start Flask servers from other ports on my machine from within WSL2 without a problem. The issue somehow seems isolated to Express JS servers, which doesn't make a whole lot of sense to me.
I have confirmed that the app is exposed on all interfaces, so localhost should be reachable.
When starting the application, I have been monitoring it with netstat -ltp. The node process does show up in the output, which indicates that the port is listening.
Are there any weird WSL2 configuration steps that I missed. The strange part is that other applications that don't use Express JS, applications seem to be running perfectly fine on all ports.
I also already have all local ports accessible through the Windows Firewall and have made the ports accessible on the Windows side via this command: netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=127.0.0.x
I have also been testing this using npx express-generator your-project-name --no-view to create a standard Express JS template.
Update:
The server is reachable from the IP address on my network, but unreachable from localhost.

Related

Deploy Create-React-App on a remote Windows Server

I am an inexperienced intern working with a remote Windows Server and React. The Windows Server is running in the company network. I have created a dynamic React website with a NodeJs backend and React Router. I have only ran it on the localhost development server. I want to try to deploy it on the remote Windows Server and give it a custom domain name (Something which can be accessed like servername/myreactapp/).
So far, I have had no success trying to make it work with IIS, even with a web.config file (I get 404 and 500 errors). I am currently making it work by actually running the development server and the nodejs server in the Windows Server, and I access it through the server IP at port 3000.
An improvement would be to be able to access the port through the server name (like servername:3000, instead of the server_ip:3000), but ideally I want to be able to access it like servername/myreactapp/.
Any help would be appreciated. Thank you very much.
The simple solution would be to run your app on port 80 then you will not have to specify the port number.
The best solution would be to set up Nginx on the server and proxy_pass / route to port 3000.
If its running on localhost, which would be port 80, the url would be like http://your_server_name:80, and would be accessible by anyone on the same network, as long as your authentication allows it.

Node.js on Google Compute Engine

I have established ssh connection. Following that, I have run my node.js application by node app.js on port 3000. It showed console output app is running http://0.0.0.0:3000 port same as my local environment. But when I opened http://external_ip:3000 it is not loading anything. How do I have to run my node app on external ip address
First of all you must have to reserve a static external IP for your VM. If you want to check whether your project is running or not open this following link.
https://[PROJECT-ID].appspot.com
Here is the guide for assigning a static external IP to a VM.
https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address

Apps running on different ports are not reachable from client side. (CentOS)

EDIT:
Issue resolved. I had to open the ports via the Plesk firewall.
I moved my node-application from my local Debian-VM to a CentOS-Server, where it also will be running in production one day.
There is the react-frontend part. Which is for development running through the react-scripts to start on port 3000 via npm start.
Then there is the backend which is just an api for fetching data and stuff, built with express.
Problem: Although starting these up throws no error at all, I can't access them through the browser or postman.
On my local VM it was just localhost + :port, but now I have an domain and I think there is the error that I don't see nor understand.
Hope someone can shed some light here. :)

TCP server won't work on Openshift NodeJS

I've used the openshift-cartridge-tcp-endpoint cartridge to try and make a TCP server which I can access from a desktop application.
I've set it up on a scaleable application and I can see the OPENSHIFT_NODEJS_PORT_TCP and OPENSHIFT_NODEJS_PROXY_PORT_TCP values when I list the environment variables using 'export' when ssh'd into my application.
The problem is, when I do 'rhc ssh APP_NAME oo-gear-registry all', no port is listed over which I can access my TCP application and when I try to access the application over the port given by the HTTP server, it does not connect. Do I have to take additional steps to make the port show up and be accessible?
It looks like that cartridge is over 2 years old, and probably doesn't work with the current version of OpenShift Online, as it only exposes port 8080 publicly and uses an HTTP/WS reverse proxy, so only http or web services connections would work. You might try logging an issue with the cartridge's creator here (https://github.com/Filirom1/openshift-cartridge-tcp-endpoint/issues) and ask them if it still works or not.

Socket.io on port 80

I've made a node application which listens on port 80, my application works fine on localhost, but when I run it on my VPS, I get a different log and a different result ( websockets just don't work )
A comparison between localhost's log and VPS' log:
Node's log on localhost
Node's log on VPS
As you see, in VPS, xhr is used instead of websocket after it says "info: transport end (socket end)"
I don't use any web server on my VPS and I ran my application as root.
Are you running a web server in front of your node app on your VPS? If so, make sure it is new enough and properly configured to do websockets. For instance, on modern Ubuntu the stock nginx is not new enough yet to support web sockets, so you have to install a separate package to get websocket support.
2nd guess: is there a proxy server between your browser and your VPS?
Have you run it as the super user on the VPS? Normal users are typically blocked from opening ports below 1024.
Our server hosted on VPS, using port 80. The io connection fired through cellular data and through WIFI fine, but in some wifi networks it didn't.
So we had used different port, then it works.

Resources