A hello world server-side application powered by NodeJS
- A google cloud platform account
- Fundamental knowledge of NodeJS
- In the Cloud Console, go to the VM Instances page.
- Click Create instance.
- In the Boot disk section, click Change to begin configuring your boot disk.
- On the Public images tab, choose Debian version 9.
- Click Select.
- In the Firewall section, select Allow HTTP traffic.
- Click Create to create the instance.
Allow a short time for the instance to start. After the instance is ready, it is listed on the VM instances page with a green status icon.
- In the Cloud Console, go to the VM Instances page.
- In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.
What is SSH?
Secure Shell (SSH) is a software standard to support encrypted data transfer between two computers. It can be used to support secure logins, file transfers or general purpose connects. Servers maintained by ITS require SSH-based connections in most cases.
sudo apt-get -y update
sudo apt-get install -y nodejs npm
node --version
npm --version
What is NodeJS?
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
sudo apt install git-all
git --version
What is GIT?
GIT is a version control system, a software tool that helps record changes to files by keeping a track of modifications done to the code.
git clone https://github.com/DSC-FPTU-HCMC/node-hello-world.git
cd node-hello-world
# install the dependencies
npm install
# start the application
npm start
# Ctrl C to shutdown
sudo apt-get install -y nginx
# navigate to configuration folder for nginx
cd /etc/nginx/sites-available
# backup your current default file
sudo mv default default.bak
# create new nginx's configuration file
sudo touch default
Edit the file default
server {
listen 80;
server_name YOUR_SERVERS_IP_ADDRESS;
location / {
proxy_pass "http://127.0.0.1:8080";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}
}
# restart nginx
sudo service nginx restart
# start application
npm start
What is nginx? nginx is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. ... In addition to its HTTP server capabilities, nginx can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.
# install pm2
sudo npm install -g pm2
# start the application
pm2 start npm -- start
What is PM2?
PM2 is a production process manager for Node. js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
- In the Google Cloud Console, go to the VM Instances page.
- Copy the external IP Address of the instance you created.
- Open new tab on Google Chrome, and paste the link into navigation bar.
- In the Google Cloud Console, go to the VM Instances page.
- Click the name of the instance you created.
- At the top of the instance's details page, click Delete.