Installing and running browserquest on ubuntu - javascript

I have installed node.js and necessary packages to run browserquest. I have started the browserquest server, which is running on port 8080 and when I go to my browser and type http://localhost:8080/status I can see that server is running and currently no clients are connected. I build the client with configurations like this in client/config/build_config.json file
{
"host": "http://127.0.0.1",
"port": 8080
}
I build my client within bin/build.sh. Then I run this command to create http-server to serve client files.
http-server path-to-client-build -p 8000
I can see the index page with the httpserver running by going to http://localhost:8000/index.html but when I try to connect it gets stuck after saying connecting to server.
NOTE: I am using this http-server to host client files http://search.npmjs.org/#/http-server

I think the client-build has some problems on the current release on github. Instead I have used the actual client folder. I have followed these steps to make it work.
Make sure you have installed node and npm.
1) get a copy from github repo.
git clone https://github.com/mozilla/BrowserQuest.git
2) Install the required node packages for the server
npm install underscore log bison websocket websocket-server sanitizer memcache
3) Start the server
node server/js/main.js
4) go to the client directory and install http-server module to serve the client files
cd client
npm install -g http-server
5) edit config_build.json-dist to point to your host ip and port (in my case 127.0.0.1 localhost)
{
"host": "127.0.0.1",
"port": 8000,
"dispatcher": false
}
6) copy the edited config_build.json-dist to 2 new files
cp config_build.json-dist config_build.json
cp config_build.json-dist config_local.json
7) copy shared folder into client folder
cp -r ../shared .
8) start the http-server to serve the client files
http-server
And your server and client should be running. You can check if the server is running by going to http://ipaddress:port/status which should display an array of connected clients. If none an empty array. And your client should be running on http://ipaddress:8000/index.html
based on the tutorial from dirkk0
https://gist.github.com/2275361

Related

In VPS with OS Ubuntu 18.04 "apt install nginx" shows libc6 & libcrypt1 error. So, how to install libc6 & libcrypt1 in it?

I am trying to host node app on vps using nginx server. But I am unable to install nginx in ubuntu 18.04 version after apt install nginx shows:
The following packages have unmet dependencies:
nginx : Depends: libc6 (>= 2.28) but 2.27-3ubuntu1.6 is to be installed
Depends: libcrypt1 (>= 1:4.1.0) but it is not installable
E: Unable to correct problems, you have held broken packages.
Anyone face such problem & how do you solve it? I also got problem in nginx.cnf, after nginx -t to check it shows brotil error.
ubuntu nginx installation
node app
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
I want to host node app to serve backend API's. So, I bought VPS from Hostinger website & have installed Ubuntu v18.04 in it. Then I successfully installed nodejs to run nodeapp & pm2 to manage processes. It was successfully running on port 8000. But problem is when I called the API from frontend, shows SSL security error.
So, for that I tried to install nginx but shows error & I guess for SSL nginx server is required. Now I am stuck in nginx installation.
I need some solution from someone who also face same problem.
You should consider upgrading to more recent versions of ubuntu as version 18.04 will reach EOL on April 30, 2023
Otherwise, you may try upgrading packages on your system, as it currently has libc6 version 2.27 while version 2.28 or higher is required.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
if you continue seeing an issue, you may try
sudo apt-get install --no-install-recommends nginx
Actually, I had installed Ubuntu v18.04 with plex control panel. I guess that is giving me the issue.
Now I installed Ubuntu v18.04 only. It is working fine now. I successfully installed nginx and it is running properly.

How to host a Node.js app on AWS EC2 Ubuntu free tier?

I am really new to AWS EC2. I hosted my Express.js on AWS EC2 using PM2.
Here is the current log of EC2 of my app.
I don't know whether this is working or not.
My public IPv4 address is (52.90.33.231).
If Nginx is required, please guide me through its steps because I have no prior experience.
I am also adding the inbound rules here.
http://localhost:5002/questapi
The above url used to give me the following data:
So
52.90.33.231/questapi is the working url.
I would prefer using Docker to run your application in EC2 instead of using PM2, It will be easy for you to migrate your application to any environment irrespective of application dependencies. PM2 is a good deployment tool but the better answer will be DOCKER.
Regarding NGINX, You can use NGINX or APACHE web servers to enable reverse proxy on your Node services to route your 5002 port to 443/80. There also I would suggest using AWS Application load balancer because it will provide the same and easy for you to install SSL certificate using AWS CERTIFICATE MANAGER.
Steps to Docker Node deployment in Ec2
Install DOCKER in your EC2 machine - Follow this reference URL
Clone your NodeJS codebase in the EC2 machine and add Dockerfile in the root folder in your codebase. Below I will add the Dockerfile sample.
Build docker image using this command in your root folder of the project docker build --no-cache -t <your_application_name>:latest .
Run NodeJs docker image using the given command
sudo docker run --name <your_application_name> -itd --net="host"
-e 5002:5002
--restart unless-stopped
<your_application_name>:latest;
Now you can start using the application on <your_instance_public_ip>:5002, Make sure to enable the 5002 port in security group inbound access.
In between, Here I'm adding a reference link to use Aws ALB to hide your EC2 IP address and application port number by using reverse proxying rules.
https://www.clickittech.com/devops/deploy-nodejs-app-to-aws/
DOCKERFILE Sample for NODEJS application
FROM node:14.0
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . .
EXPOSE 5002
CMD [ "node", "server.js" ] # you can add your start command
you should refer to this video (from Brad Traversy) where he deploys the Nodejs application on DigitalOcean droplet using pm2, but for deploying on AWS EC2 you can follow the exact same steps as both use the Ubuntu OS, NGINX and pm2 for configuring the application.
NODEJS DEPLOYING TUTORIAL

how to deploy nodejs api and vuejs app in one server

I have developed node rest api and vuejs web applications,
Im trying to deploy both project in to one aws server which run ubuntu.
Both applications have different port,
domain I try to configure api.example.com for api and example.com for vue app.
I can run both applications once after running the command in SSH, but I need them to run it forever.
What I did,
Deploy to apps separately
Apps can access with ports
I need them access
api.example.com
example.com
what are the step to do,
Any changes host file.
I found another way to deploy vue app and express/nodejs in one server without using PM. This what I did
Build your vue code using npm run build command. This will create a folder dist which should have index.html file and static folder.
Copy dist folder into your server code repository. In my case I created a folder public and moved the dist folder inside public.
In app.js file right before module.exports=app line, copy the following lines of code
//These 2 lines make sure that vue and express app are coming from the same server.
app.use('/static', express.static(path.join(__dirname,"../public/dist/static/")));
app.get('/', function(req,res) {
res.sendFile('index.html', { root: path.join(__dirname, '../public/dist/') });
});
First line make sure that the /static folder is accessible and second line will serve the index.html file when you run the node server. Routing between components will be taken care by vue.
This is how we are running our VueJS UI and ExpressJS REST API from the same server.
We are managing our services with PM2.
VueJS (Dev Environment, You can add the same settings to production)
In package.json add "start": "HOST='0.0.0.0' PORT=80 npm run dev",, where 80 is the port VueJS is listening on, to the "scripts": {..} array. Then, after installing PM2, (for dev) we can start VueJS with cd /location/of/vue/root; sudo pm2 start npm run dev --name Vue -- start. (Make sure that Apache is not running).
Please note that setting the HOST to 0.0.0.0 is important. Do not set it to LocalHost or your Servers IP address or you may run into issues.
ExpressJS
In the /location/of/express/app.js add this similar to the bottom of the file:
app.listen(process.env.PORT || 8081), where 8081 is the port your REST API should be listening on. I can then start it with sudo pm2 start /location/of/express/app.js --name Express
At this point, the VueJS should be available at www.example.com (implied Port 80) and the REST API would be available at www.example.com:8081.
If you want to have api.example.com/ point to the API, you need to make sure that your DNS is pointing the "api" subdomain to the desired port, or you may have to add the port into the URL as above.
Additionally, you can easily follow the logs through PM2 as well with pm2 logs APPNAME --lines 100.

Cannot access React app from production server

I have a react app which I can run on localhost without any problems. I dockerized it and put it on the production server, and sudo docker ps shows that the container is running. I used sudo docker run --name "name" -d -p "my port":my port" "uri"
to run the container, and I made sure to specify the correct port. But when I try to access the app from my browser by putting in the ip of the server and the port, I cannot access it. I am able to access other apps running on this server.
Any ideas as to what I'm doing wrong?
Just verify the return of your container, when you run it. Try:
docker run --attach STDERR ****
The command in my start script setting the port to be different than the default 3000 was not working in the docker container, although it worked when I ran the program on localhost. So instead, in my run command, I mapped port 3000 to the port I wanted to use on my server.

node.js url without port number

I'm creating node.js project now. I've a VPS which ubuntu 16.04 as op system and nginx as http server installed on it. As you know we use URL with port number like http://localhost.com:3000 to access our node.js projects. I wonder is there any way to access without port number like http://localhost.com like normal php and other projects?
Solution 1
Use Apache or Nginx as a reverse proxy.
Apache: https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04
Nginx: https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-16-04-server
Solution 2
Forward port 80 to port 3000 with iptables
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
References:
https://www.digitalocean.com/community/questions/how-can-i-get-node-js-to-listen-on-port-80?answer=5772
https://stackoverflow.com/a/16573737/1728166
The only reason we use those kinds of port numbers for local development is because ports under 1024 are "reserved" and require root permissions to be used. You can still use port 80 for local development if you set your node server to listen on this port.
If you do make these changes to your node server, in order to run it locally you will need to run it as root or using sudo.

Categories

Resources