How connect to Html page with node.js server and aws virtual machine - javascript

I'm trying to install a node.js server for a sentiment analysis service with my Twitter account that retrieve the tweets on my profile and provides a statistical output and saves them on a Mongo db istance.
I have uploaded my node.js code on an AWS virtual machine with an public IP address and with the permission to create an endpoint with HTTP and HTTPS protocols.
I have installed successfully the node.js code on AWS virtual machine with Windows Server 2019 OS, with the npm install -g -n command with 0 dependencies errors, and when I try to connect to the AWS virtual machine with http://ip_public_address:8080 I get the error "impossible to connect - err-connection_timeout".
This is the link to the github project that I need to install and to work on AWS virtual machine:
https://github.com/thisandagain/sentiment
Maybe I am confused about how to connect with the index.html page via AWS virtual machine and I don't know if this page must be retrieved with a IP public address or localhost parameter and what is required, at node.js level code, in order to enable the AWS virtual machine to respond to my browser with the content of index.html page.
Please can you give me advices about to implement successfully this project?
Thanks
Filippo

You don't mention security groups in your question at all, so the likely cause is that you never opened port 8080 in the security group assigned to the EC2 instance. You may also need to open that port in the Windows firewall on that server.

Related

How do I make my electron apps communicate locally between different machines

I have two electron apps. One is a server on machine1 and another is a client on machine2.
When I start the server from the electron app on machine1, I want machine2 (the client) to be able to be able to receive and send data to machine1 (the server).
I tried using http://localhost approach which works for the app during development but doesn't work for the packaged app which is installed on the machine.
Please help. Thanks
When you package an Electron app, it is no longer running on localhost, it runs on the IP address of the machine on which it is installed.
To establish communication between the server and client apps, you will need to use the IP address of the machine on which the server app is running. You can use the os module in Node.js to determine the IP address of the machine on which the server app is running. Once you have the IP address, you can use it to connect the client app to the server app.
You can also use a package like ip to get the IP address of the machine.
const ip = require('ip');
console.log(ip.address());
Hope this helps.

I want to deploy Node.js & React.js projects in same domain and server

As per my Title, I want to deploy Node.js & React.js projects in the same domain and server.
Basically, I want to host the application on cloudways server. https://www.cloudways.com/
I try to host there but due to the same domain action, it is not working as working in the local environment.
Front-end screenshot with package.json script structured(React.js): https://prnt.sc/xT4NAPxt0S99
Back-end screenshot(Node.js): https://prnt.sc/mSg_H4O6prF0
The given screenshot is from a local machine.
As you see here https://prnt.sc/xT4NAPxt0S99 we are using npm run build and after doing the build, we move that folder to the server folder and run npm i && nodemon index.js. It is working well in a single domain or IP in the local server well. But when I do the same process on a live server, it is not working.
Why I am using cloudways server?
For this, I don't need to install and set up MySQL, Node modules, PHP, and other things. Cloudways is doing all things when we create a cloud server.
npm i don't need to run this company on a server.

How to get SSL certificate for homemade webserver

I've created my own webserver using Node.js ans is using it with my DNS from webhost routed to my raspberry pi at home.
How do I prepare the webserver and all the files for getting an SSL certificate using Let'sencrypt?
I've not made any work prior to getting the SSL other than creating the server to run on localhost. Now it's running on a public ip while using my purchased DNS.
I haven't been able to find any litterature other than the off the shelf webservers like apache and such and I really want to run with my own.

how can I connect to a http://localhost:4200 using browser which is a aws ec2

I am learning node.js in an online course to build up a web server and app
before the teaching started, the teacher told me to set up your coding environment, and it got a direction to told me what to do step by step.
Because I using Chromebook, So I started an aws ec2 serve which is ubuntu 18.04 and using cloud9 for my ide
I installed node.js successful on the ec2
And the direction told me to type on those on the terminal
git clone https://github.com/OpenClassrooms-Student-Center/5614116-front-end-app.git frontend
You can then do the following:
cd frontend
npm install
ng serve
This will install all the dependencies needed by the front end app and will launch the development server. Now, if you navigate to http://localhost:4200 , you should see the following (assuming you've followed the steps above successfully):
the direction say if I successfully followed the step, will see something on http://localhost:4200
On the terminal, at last show me
ℹ 「wdm」: Compiled successfully.
But how can I connect to http://localhost:4200 which was an ec2?
I tried using IP:4200, the browser keeps on loading the page and nothing shows up on the browser
----------------------------------------
I found out that the program that teacher gave me to install set the URL to http://localhost:4200
because cloud9 says the program was running, but running at a URL call http://localhost:4200
what should I do?
Localhost refers to your local machine. But as mentionedd that your node.js running on ec2 and want to connect to it from your browser, get the IP of the ec2 and type in your browser- IP:4200
And it should work
The only problem here is you have to add port 4200 in your aws ec2 instance security group to allow inbound traffic.
STEPS:
1. Go to your EC2 instance.
2. Click security group from Description below.
3. Click Inbound then Edit.
4. Click Add Rule
5. Select Custom TCP , Port - 4200 , IP - 0.0.0.0/0
6. Then SAVE.
After that try <EC2-IP:Port> in your browser it will work fine.

How to run node.js in my web site server not my pc local server

Last 2 days I spent more time and read 50+ articles and video to understand node.js and after installation now I can see the result in browser by http//:localhost:3000/ But I have confused in many case that I describe below.
I do all of my work in my share hosting server where I my keep my web site: www.myweb.com
In every article about node.js, they are teaching how to get a result by below code in a browser by http//:localhost:3000/ in local pc server.
test.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
But My Question:
If I use http//:www.myweb.com/test.js` in my browser, What will be the above code?
In case of local pc we write on npm node test.js, But In case of hosting server when any clint open the page like http//:www.myweb.com/test.js How to work it?
In case of php we used include ("head.php") to got something from that page But In this case How to make a call on node.js.
Well, what you need to do is understand how http web servers works.
Usually, on your remote machine (your server), you have an instance of a web server (ex : apache) running, which is listening to port 80 (standard port for http requests). It will handle every request made on that port, and manage routing to use the correct php/html file.
Then, it will run the php code server-side, to render an html file and serve it to the server. So the client will not see the php code at all.
Let's talk about Node.js. Node is an application that runs javascript code server-side, and can run an http server with using some modules. But the javascript code will never be shown to your client, he will only get the http response you send him (typically, the html page).
So now, with node.js, you need to do the same as the apache server did, by creating the http server. First, what you have to know is that not that many website host are offering node.js, or even console access. They usually serve the php/html files you put in the configured folder, and that's basically it. What you need is either a virtual machine, or a server on which you can install node.js and run it, or use a node.js hosting service, like heroku or nodejitsu to host your node.js http server.
So, to create the node.js http server, you need to create an http server (as you did in your code), and make it listen to port 80. Now, every http request send to your server will be handled by your node.js instance. Then, you can do anything you want with that request.
I hope I haven't been to messy.
You need to install NodeJS on the server. If this is shared hosting where you cannot install additional software then you will be unable to use NodeJS. In that case contact support of your web hosting company and inquire about NodeJS support.
On the other hand, if you do have root user or super user rights on a system, you can install NodeJS. For example for on CentOS/RHEL systems you can install using yum with the following commands.
sudo yum install epel-release
sudo yum install npm
For some of the other distributions of Linux: http://ask.xmodulo.com/install-node-js-linux.html
To access Node applications from your PC to the server, you also need to open a port in the server firewall that your Node aplication uses.

Categories