Node.js on Google Compute Engine - node.js

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

Related

Express server unreachable from browser when running in WSL2

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.

node inspect on google cloud console setup firewall

I am trying to setup the firewall for accessing node inspect using my local chrome browser.
Does anybody have a good short guide and which tcp protocol do I need to enable.
I have a firewall rule active where the compute instance enables tcp:80. It worked in the past of a http server. How do I know which port to use for node inspect and how to enable it.
If found it myself. I have to use an ssh tunnel. https://nodejs.org/en/docs/guides/debugging-getting-started/#enabling-remote-debugging-scenarios
Enabling remote debugging scenarios
We recommend that you never have the debugger listen on a public IP address. If you need to allow remote debugging connections we
recommend the use of ssh tunnels instead. We provide the following
example for illustrative purposes only. Please understand the security
risk of allowing remote access to a privileged service before
proceeding.
Let's say you are running Node on remote machine, remote.example.com, that you want to be able to debug. On that
machine, you should start the node process with the inspector
listening only to localhost (the default).
$ node --inspect server.js
Now, on your local machine from where you want to initiate a debug client connection, you can setup an ssh tunnel:
$ ssh -L 9221:localhost:9229 user#remote.example.com
This starts a ssh tunnel session where a connection to port 9221 on your local machine will be forwarded to port 9229 on
remote.example.com. You can now attach a debugger such as Chrome
DevTools or Visual Studio Code to localhost:9221, which should be able
to debug as if the Node.js application was running locally.

how to run nodejs in google compute engine external ip with 2 separate port

I'm facing an issue.
I have created vm instance on google compute engine. vm instance external ip is: 104.198.225.177. accessed ssh and installed nodejs. now I want to run 2 nodejs script one in port 8000 another in port 9000.
if want to run and access 2 nodejs url like this: http://104.198.225.177:8000 and http://104.198.225.177:9000
I have created script but when I start and try to access in browser using vm instance external ip, like : http://104.198.225.177:3000/ but its not working. I tried in ssh cur like : curl localhost:3000/ and its working but using external ip its not working.
when I add ip address while starting nodejs like this:
app.listen(9000,"104.198.225.177"); I'm getting this error:
listen EADDRNOTAVAIL 104.198.225.177:9000 at Object.exports._errnoException
any help appreciated.
Ensure that you've allowed traffic from external sources to reach certain ports of your GCE instances in Networking Firewalls section.
Solved: Also ensure that your application is bound to 0.0.0.0/all interfaces and addresses, not just VMs public IP address.

deploying WT web app on google cloud

I have build a wt (witty) hello world example and I am trying to deploy this on a Google Cloud instance. It seems to run fine locally (hence it has all the necessary library dependencies). However, I am not able to it to deploy on the server.
I am trying (using my actual http address which is different from the example below)
./hello --docroot . --http-address 105.150.47.754 --http-port 80
but it responds with
Error (asio): bind : cannot assign requested address
It seems to work fine using (0.0.0.0/0)
The cloud instance allows HTTP tcp/80 traffic.
I have tried
setcap 'cap_net_bind_service=+ep' ~/hello
to allow non-root users to publish on ports below 1024, but also to no avail.
Any suggestions?
Cheers, Mike
If you are unable to listen on the specified IP address, one of the following is likely true:
1) Something (such as a web server) is already listening at that address on port 80, or
2) The IP address you are using is not assigned to one of the machine's network interfaces.
Using (0.0.0.0/0) with port 80 tells the Wt web server (wthttpd) to listen on all available local interfaces. Therefore, using that address will work with any available network interface assigned any IP address with port 80 available.

windows azure sdk localhost for node.js

I am running a helloworld program using node.js and windows azure sdk.
If I keep : 127.0.0.1:81
This link works and I get the hello world printed on the browser.
But when I try:
--http://192.168.1.6:81/
This link is not working. 192.168.1.6 is the localIP of the machine I am running this application.
Can you please let me know how I can get this working with a IP address
I have the node.js helloworld application from:
http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/
before I deploy this in cloud I want to run my application with the IP address of the host
The compute emulator specifically binds to 127.0.0.1 and not any other IP addresses, so there's no easy way to do this. (Workarounds like port forwarding are possible, but I wouldn't recommend doing it unless you have a good reason why you have to.)

Resources