Introduction
Every cloud provider supports open source stacks for web development, and Alibaba Cloud is no different in this manner. Alibaba Cloud provides hosting support for major frameworks like .NET Core, Python, Node.js, Ruby and more. Node.js is the most loved and most used web development stack for the JavaScript programming language. It powers some of the most used front-end development libraries too, including React.js, Vue.js, and Angular (Angular uses NPM to distribute the Angular CLI). Several community-driven and developer-friendly web development runtimes/frameworks have shown up in the last few years, including Express.js.
In this article, we will walk you through the deployment and hosting of a Node.js based web application on the Linux environment.
The source code used in this article is available on GitHub.
Prerequisites
This article will cover the deployment and hosting aspects of Node.js, so you will need to:
- Know the basics of Node.js web development. Node.js is very easy to learn and get started with, you can read this articleto get to know the basics of Node.js.
- Know the basics of the gitversion control system and its command-line interface. This article uses beginner level git commands only.
- Set up an Alibaba Cloud account to create a hosting service for the Simple Application Server.
You can create a free account with Alibaba Cloud with $20 free credit and create your web server. You can also use a local virtual machine if you find it helpful.
Next sections assume that you have a Node.js web application. You can use the code for the Node.js app from the GitHub link provided above.
Simple Application Server by Alibaba Cloud
Alibaba Cloud provides multiple services to customers for hosting purposes. Ranging from ECS to Scalable Kubernetes services, customers can decide how to deploy their applications. Simple Application Server is a managed ECS service by Alibaba Cloud. It offers:
- Managed ECS instances in a cheap package.
- One-click deployment for open-source products; WordPress, Drupal, and more.
- Custom domains and SSL certificates.
- Web firewall rules to prevent unauthorized access.
- Service backups and restoration.
- In-browser VM access software; Rescue Connect.
These options make this service a suitable candidate for hosting needs. Simple Application Server supports virtual machines in all major Linux distros and Windows Server 2008, and 2016 editions (at the time of this authoring, and it might change in future).
Step 1 - Creating a Deployment Environment
We recommend using the Ubuntu LTS image for the hosting environments as they provide a stable environment, and major web runtimes support them. To create a new instance, go to Simple Application Server on Alibaba Cloud. You can search for Simple Application Server on the main page,

You can also visit the service directly using the link we provided above. Depending upon your orders you might find your resources listed on the page or an empty page. We have created a few virtual machines, so we are provided with two virtual machines.

Adding a Service Subscription
You can create a new instance using the "Create Server" button in the top right corner of the page.

Click on this button to visit the service purchase page. This page will show a list of all services and products. You can create an application using open-sourced products, such as WordPress.

You can also create a vanilla virtual machine using OS images, such as Windows Server or Linux distros.

Select a Ubuntu 18.04 image for your service.
At the time of this authoring Ubuntu 18.04 is the LTS release.
In the next step, you should select the instance size for your machine.

For development/testing purposes, you can use a 1 vCPU and 1 GB RAM instance. For production environments, we recommend using at least 2 vCPU and 8 GB RAM for optimal performance. Your virtual machine contains a data disk where the data does not persist. You should consider adding an extra data disk to your subscription. This extra data disk will help your applications persist the data in case of a crash or a reboot. After this, you can place the order, and Alibaba Cloud will create a new resource for you.
Linux machines are half the prices compared to Windows machines and provide better performance on Node.js and .NET Core instances.
If you want to use a virtual machine, then you can visit this link and learn How To Install Ubuntu Using VirtualBox On Windows 10.
Step 2 - Setting up Deployment Environment
After you have created the deployment environment, you need to install the required packages to host a Node.js application. On a fresh machine, you will need to use the git version control to get your source code from a remote repository. First, connect to the virtual machine instance using Rescue Connect service inside the portal or via SSH.

You can use the "Set password" to reset the password for your SSH account. Then you can use any SSH client to connect to the virtual machine. PuTTY is one of such clients that are widely used. You can learn how to use PuTTY from this link.
Once you have established the connection, SSH will show you this screen on PuTTY — or your favorite SSH client.

First of all, we need to refresh the repositories that Ubuntu uses for our packages and applications. Run,
$ sudo apt-get update
Now execute the following command to set up basic build SDKs on Ubuntu.
$ sudo apt-get install build-essential
This command installs C++ and other native SDKs on Ubuntu. Node.js uses these SDKs to install and set up the NPM packages upon npm install.
Now we need to install git, so we can fetch the source code and host it. To install, run,
$ sudo apt-get install git
Now we only need Node.js on our environment. Ubuntu 18.04 comes shipped with a repository for the Node.js package. We can just execute,
$ sudo apt-get install nodejs npm
We also installed the NPM — Node Package Manager — that will help us in managing the Node.js packages and generate scripts to run Node.js apps. After this command, verify your Node.js and NPM package versions. Run,
$ nodejs --version
$ npm --version
You will see the following output,
root@iZp0w3npg0fhgu06dyhmboZ:~# nodejs --version
v8.10.0
root@iZp0w3npg0fhgu06dyhmboZ:~# npm --version
3.5.2
root@iZp0w3npg0fhgu06dyhmboZ:~#
This confirms that our hosting environment is ready to accept our Node.js web app.
Step 3 - Deploying Node.js App
There are many ways in which you can deploy a Node.js app. You can use DevOps and automation tools to create a CI/CD pipeline, or you can deploy the files directly on a server using FTP. We will not talk about any of those in this — as we have planned for more articles that will talk about automation and CI/CD. We will use git CLI to fetch source code and then host it manually.
Now, we can create a directory to contain our web application and host it using the nodejs process. Execute the following commands to create a directory,
$ mkdir hosting
This will create a directory called hosting in the root of your virtual machine's file system. Enter the repository,
$ cd hosting/
You can copy the content of the Node.js application here. Since code is available on the Git repository, we use the git command to pull the source files,
$ git clone https://github.com/afzaal-ahmad-zeeshan/nodejs-dockerized app
Cloning into 'app'...




Dipa MehtaPosted Nov 23, 2019, 7:18 PM
Good one Afzaal ...
Sourav Kumar DasPosted Nov 23, 2019, 12:48 AM
Nice article Sir.
Chittaranjan SwainPosted Nov 22, 2019, 9:27 AM
Nice article.