Network Error when I try to run React web on AWS - node.js

Sorry maybe it is a dump question but I could not go further.
I got a website which already built with ReactJS and working on AWS Ec2
When I run on localhost
First; in terminal which in file directory run node server.js
yarn start
then I can see the localhost:3000 then when I make any changing just send with SSH and run server with PM2 which pm2 restart server
My question is I want to create a second AWS EC2 instance and run the code there as well when I change config.json which domain is store there I can see a NETWORK ERROR
I created a ec2 instance copied all my files there and I installed NodeJS npm and pm2 but I could not managed see my website on localhost:3000()
What Do I have to do?

You need to use the EC2 public address/IP not localhost

Related

Is there any way to manage node.js server from web interface?

I am in need to manage my node server without entering into server console. I have tried using forever, nodemon and pm2 npms. Whenever, I need to start or stop the node application, I need to connect the server via terminal. I want to avoid that and willing to see the possibility if that can be managed through any web interface or any browser plugin/extension.
Already tried forever, nodemon and pm2
You can use npm pm2-gui install it by this command npm i pm2-gui
See the docs and guides from here https://www.npmjs.com/package/pm2-gui
I started looking for some GUI and Web interface of PM2. Tried several npms but "mc-pm2-web" worked really good for me.
I am using Node via NVM and my node version was v10.15.3. Installed this https://www.npmjs.com/package/mc-pm2-web and it was straight forward what I was actually looking for.
Here's are the step if anybody wants to install and configure "mc-pm2-web" in AWS EC2.
I am using Amazon Linux
I am using NVM and running v10.15.3
Already had NGINX & PHP-FPM running on server using port 9000
pm2 already installed
Visit this link:
https://www.npmjs.com/package/mc-pm2-web
npm install -g pm2-web
pm2-web
If you encountered any error then you may check your config.json file. In my case the config file path was:
/home/ec2-user/.nvm/versions/node/v10.15.3/bin/pm2-web/config.json
I made following changes in config file to make it working:
Port from 9000 to 9010 because 9000 was being used by PHP-FPM
Changed the host name from "localhost" to "my-domain" which was already hosted in NGINX
Enabled authentication and set the Username and Password for making it secure
Allowed 9010 port from AWS EC2 firewall / security group of that instance
Added pm2-web in pm2 by executing "pm2 start pm2-web" command

Node.js app stops working as soon as the AWS Lightsail's Bitnami console is closed

I have developed a simple node.js application and I am trying to publish it on AWS Lightsail. I followed the instructions on this page: https://medium.com/#sharmasha2nk/aws-lightsail-bitnami-nodejs-letsencrypt-cf653573b8a1
I am connecting to Bitnami using the SHH console provided. After I start the app with node index.js command the app is up and running until I close the SHH console. As soon as I close it the application stops and “Service Unavailable” error is being displayed. How can I keep my app running on AWS even if my PC is shot down and the SHH console is closed?
I have tried restarting the apache server and AWS Lightsail instance. Neither of them helped.
httpd-app.conf file content:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
httpd-prefix.conf file content:
Include "/opt/bitnami/apps/emsnotes/conf/httpd-app.conf"
Thanks.
I would recommend you pm2
Here's how to do it quickly:
install pm2 globally using sudo npm i -g pm2
navigate to the location of your index.js via ssh
run pm2 start index.js
This will keep node running even when you disconnect the ssh session or shutdown your development computer. The process will keep running on your server in the background. This is used for running node apps in production on a server.
You can read all about it here in its documentation.
I hope I could help you, please let me know if you have any question.
Karim
I had a look at the article and frankly i see nowhere that he talk about keeping the server up and running.
Basically he is using the Bitnami Node.js stack and if you look at the docs you will see that Bitnami use Forever.js to keep the apps running on their instance, Forever is a CLI tool to monitor and keep a Node instance running in the background.
Check the docs here : https://docs.bitnami.com/general/infrastructure/nodejs/administration/start-express-server/
Here is the Git for Forever, so can read more on it: https://github.com/foreverjs/forever

Connecting app to AWS EC2 instance

I'm pretty new to DevOps and I'm trying to set up my Node.js app on a AWS server instance. Steps I've taken:
Set up Elastic IP
Launched EC2 instance with Ubuntu server
Connected IP to instance
Allowed incoming connections on port 3000
SSH'd into the server with a .pem file
Now I'm at the point where I need to get my files uploaded to the server. I've used FileZilla (and like it) in the past to upload files but the initial part was already set up. When I set up the site on FileZilla there is no /var/www folder on the remote site.
Don't know how to connect these dots.
Also not sure what I need to run once I successfully upload the files. I imagine npm install when I'm ssh'd into the server? Most of the tutorials out there only go through the basic instance setup.
Thanks!
You don't need to have /var/www. Also, it's better that you use a version control and a remote repository like Github and then SSH to your EC2 and then clone your repository there.
Then cd into your repo and run npm install and then start your app.
And check.
Once you connect to the EC2 instance then clone your code in there. It not mandatory to be in /var/www/html but, it's best practice to keep it there. Once you clone npm install into your project home directory so all the required packages get installed. Then for running your node application in production you have to run it on service as pm2, supervisor, forever, passenger, etc. You can use any of these services and configured appropriately to run your application on desired port. As with pm2, you can follow this guide, install pm2 Then you can run with the following command w.r.t. your environment, like I want to run my application on port 5555 for production
$ PORT=5555 pm2 start app.js --name API --env production -f
Check the status using pm2 list Now, your application is running on http://server-ip:5555/ But, you won't be typing port number every-time. So, you need to configure the web server in front of your application like apache or nginx which will forward all request to your application running port. You could find the best guide to their home page. Then your application is available at http://server-ip/ You can follow this for single configuration of multiple node apps
Hope this helps.

pm2 is not working in amazon ec2 with node application

I have node application hosted in amazon ec2.
I used nginx to point it in my domain.
It runs perfectly when i use npm start to run the application.
But when i use pm2, it doesnt work.
pm2 list command shows that the app is running.
But url doesn't work. Even when i again run npm start app gets started that clearly states that the port is free. So pm2 is not actually running anything on that port. But pm2 says app is online.
I was running the wrong file from pm2. As it was express project, so i had to run bin/www
So the following command solve the issue:
pm2 start bin/www
Answered it here as well:
https://github.com/Unitech/pm2/issues/3252
Thanks

Running pm2 on Elastic Beanstalk in cluster mode

I've been trying to run pm2 on AWS Elastic Beanstalk's node web service environment but without luck. I start up the express api via: ./node_modules/.bin/pm2 start server.js -i 0 but the server never comes out of a Degraded state. I can run this same command locally just fine. I have ssh'd into the aws instance and looked in the logs, but I don't see any errors. It would be a big help if I could chat with someone that has successfully run pm2 on eb via cluster mode.
Thanks!
I have successfully deploy pm2 on aws elastic beanstalk, it has more than one way to achieve.
You may either add an installation command to the .elasticbeanstalk/config.yml file for pm2 global installation or simply install pm2 into your app and follow the instruction of the link below (recommended way).
https://gist.github.com/Unitech/4c8ea564aa8bf0a389c5
As for the first method, in your config.yml file, simply add the following line(the link above doesn't require this) :
container_commands:
0_install_pm2:
command: "npm install pm2 -g"
You need to manually handcode the start command for your app with this method.

Resources