Running node app digitalocean and accessing it - node.js

Im running my node app with grunt on a DO droplet. I start the server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:3000
But when I navigate to my dropletIP:3000 I cannot see the app, I get:
This site can’t be reached
mydropletIP refused to connect.
Shouldn't my app be available? I don't have nginx or anything installed.

I was having similar problem but the solution was simple. Change from 'localhost' to '0.0.0.0' i.e
.listen(8080, '0.0.0.0');
And then to test your api just enter your static ip of droplet with port that you have entered i.e droplet-ip:8080

Check the particular port is opened or not ,using following command
sudo ufw status
If any Firewall enabled and any port is block means you can see that.
netstat -an | grep "LISTEN " ( List of listening port on server)
I need this info ,then only we can find a problem

Related

Access NodeJS server installed on Linux server

I created my App from this boilerplate
https://github.com/Bikranshu/express-react-boilerplate
Now I uploaded it to a live Linux server and Node server is running.
Screenshot of running server
But I am unable to access it through Browser with IP address of server.
http://ip_address:3000
After waiting long in browser it is showing timeout error.
Please guide me how can I access the node/react app from browser.
Server running at <ipaddress> is a local IP, are you in a different network than the server? If so, you should be typing https://<public ipaddress>:3000
UPDATE
Hosting services usually only forward port 80 (http) or 443 (https.) This means that your port 3000 is not allowed for public access. To fix your problem you need to change the listening port.
Check line 42 on
server/app.js change 'port' to "80" or check package.json and edit npm start to set port to 80

Serve node Webapp on port 80 in amazon ec2

I have a node application listening on port 80, I have set the security groups open on port 80.
But, when I access my webapp in browser via public ip(http://xx.xxx.xx.xxx/), it doesn't show up.
What could be the issue?
I've use this doc as a guide https://aws.amazon.com/premiumsupport/knowledge-center/connect-http-https-ec2/
When your security group already allowed traffic It means something wrong with the instance.
The first step to debug such an issue to verify the application status inside the instance.
do ssh to the instance and verify is the instance responding on localhost curl localhost
check is the process running, if you are using any nodejs process manager like pm2 pm2 list or forever forever list or ps -aux | grep node
Verify is the server running on port 80.
check is the port occupied netstat -antu | grep LISTEN
In short, if the application responding on localhost using curl localhost, then as mentioned in the comment then the instance is in the private subnet.
you can check this article to know about public and private subnet.
So The answer was, my security groups were fine. My app wasn't running because I didn't set the environment variable correctly. sudo PORT=80 node server.js was the command I needed.

nodejs app wont create server, says ERR_CONNECTION_TIMED_OUT

I'm trying to run a nodejs app on my VPS but for somereason I get a ERR_CONNECTION_TIMED_OUT error.
Here is my code:
const http = require('http');
const server = http.createServer((req, res) => {
res.end();
});
server.on('clientError', (err, socket) => {
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
server.listen(8000);
when i cd to my directory and do
node index.js
, it gives me no error, but going to the browser and doing: mysite.com:8000 gives me nothing. The connections times out
EDIT:
when i do curl: enomshop.tk:8000, I get some feedback. Its like i can access from the within the VPS but no access publicly
This is the way you should go about resolving such issues
Check if the process is running
Run ps aux | grep <process> to check if your process is running
Check if the port is being used
Run sudo netstat -plant | grep <port> to check if port is listening or not and is it your process
Check if the service is responding locally
Run telnet 127.0.0.1 <port> and make sure you get a response. If you don't get a response then there are few possible issues you can look into
The process is not started the server listening
The process is not using the correct port
There is a firewall that is blocking the port. There is this for firewall-cmd, and this for ufw
Check if the service is responding externally
You can do telnet <external ip> <port>, if it doesn't work then there few things you should check below
Make sure your server is binding to 0.0.0.0 or <private ip> and not 127.0.0.1
Make sure the VPS server you are hosting on, has your <port> enabled for communication. This is different for each service provider
If you follow these steps, it would solve most common network issues in such cases
I was facing the same issue. To resolve that, just open up / allow the port from network security group (VPS) or Firewall to worldwide access.
And check telnet mysite.com port, it worked for me. Kindly let me know if you still face any issue, I will try to help further.
You will need to open up the 8000 port on your VPS or redirect the traffic from any open port on VPS to 8000

NodeJS on Port 80 Randomly Stops Working

I recently began working on a small Node website on my computer, and it has been running fine for a few days on port 80. I am able to connect to localhost, 127.0.0.1, 192.168.1.2 (my network IP address) and my public IP address (I have port forwarded) I restarted my computer, ran the program from console with Admin permissions and now when I connect to 192.168.1.2, or my public IP address, Chrome gives me the error: "No webpage was found for the web address: http://192.168.1.2/" IISNode is an alternative, but I have had lots of trouble setting it up. Netstat indicates port 80 is not blocked, and I have removed the default website from IIS. Port 80 is open on YouGetSignal. Express is started on var server = app.listen(80, "0.0.0.0"); I have restarted my computer a few more times. All of my research has yielded nothing. What could be going on?
Using Command Prompt in Admin, is issued netstat -aon | find ":80" and there was a process using port 80. I then issued Taskkill /PID <YOUR PID> /F because the process didn't show on task manager. The issue was then resolved.

How can I find where node.js is running?

I have a VPS with node.js installed, I already uploaded a basic example to test it on the server, so I tried doing this:
I access by SSH, navigate to my project folder and run
node app.js
I get this message
Express server listening on port 8080
I thought i could see my app here
example.com:8080 or server.example:8080... but nothing. Then I tried with the info from os.networkInterfaces(); and os.host(); and still nothing happen
could you help me out? as you can see I am a total noob on node.js. What I'm doing wrong? or what should I do before running my app? Something related to DNS's? i have no idea
How do you ssh to your host? with ip or name? Is it something like:
ssh root#example.com
if so then at least you know your DNS is ok.
Once on the server do a
netstat -a
if you find *:8080 then your server is listening in the default ip. If you see something like 12.23.45.67:8080 then this number is the ip your server is listening.
ifconfig
will give you the servers ip. This should be the same as the ip of example.com. If not then maybe there is some router/firewall in front of your server and you have to configure that to allow port 8080 to reach your server.
if someone ever has the same problem this is how i solved on CentOS:
Open this file
/ Etc / csf / csf.conf
Add the required port
Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,26"
Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873"
Restart
# # Csf-r

Resources