Developing Node.js App in Visual Studio and Deploying on Simple Application Server

By Arnab Choudhuri, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

This article is meant for individual developers or startups with developers who are not familiar with deployments and use PaaS for the same. In this article we look at the steps one has to do to develop their Node.js core applications in Visual Studio 2017 and deploy the same on Alibaba Cloud Simple Application Server.

Quick FAQ

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs, as well as websites, web apps, web services and mobile apps. It is one of the best IDE available in the market for node.js with project templates, intellisense, npm integration, advanced debugger, profiler, Unit testing and TypeScript integration.

What Is Node.js?

Node.js is an open-source, cross-platform JavaScript run-time environment and allows you to run JavaScript on the server.

What Is Git?

Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files.

What Is GitHub?

GitHub is a web-based hosting service for version control using Git. It is mostly used for computer code. It offers all of the distributed version control and source code management functionality of Git as well as adding its own features.

What Is Alibaba Cloud Simple Application Server?

Simple Application Server provides you the all-in-one solution to launch and manage your application, set up domain name resolution, and build, monitor, maintain your website with just a few clicks. It makes private server building much easier, and it is the best way for beginners to get started with Alibaba cloud.

Developing Example Application


If you do not have one already, click on this link to sign up.

Visual Studio 2017 and the Node.js development workload

To install Visual Studio for free, visit and while installing do select node.js development workload

If you already have visual studio but need to install the workload

select File > New > Project
click the Open Visual Studio Installer link in the left pane
select node.js development workload
select modify

Create node.js project from template

Edit and Change Code

Select index.js under the folder routes.
In index.js, go to the line of code containing res.render

Change the line as below

res.render('index', { title: 'Simple Application Server', data:'Alibaba Cloud' });

Select index.pug under the folder views.

Change title to data in the line containing Welcome to as shown in image below

Run Application

Note: The application in browser starts on port 1337. This is because in file app.js the following line of code

app.set('port', process.env.PORT || 3000);

The application reads the VS config file to get process.env.PORT which has value 1337. But on the Alibaba server, the application will run on port 3000.

Push Your Local Project on GitHub

You could also use GitHub Extension for Visual Studio (install from to push the code to GitHub.

But I prefer to use command line to do these.

Create Empty GitHub Repository

Add Repository Name and Description and select Create Repository

Your empty GitHub repository is created. Please do note the remote repository URL as you would need the same later.

Add Code to Local Git Repository

Initialise the local directory as Git repository.

git init

Add all the files in the local directory to staging, ready for commit.

git add .

Commit the staged files

git commit -m "first commit"

Push Code to GitHub

git remote add origin My-GitHub-repository-URL

(In our case we replace My-GitHub-repository-URL to

Push local repository to the remote repository we added earlier called “origin” in its branch named master.

git push -u origin master

You can now see all your files in the GitHub repository.

Create a Simple Application Server Instance on Alibaba Cloud

Log In and Select Simple Application Server

Log in and select Simple Application Server under Products

Click on buy now/ Create Server to start the process of configuration setup

Setup Server Configuration


Select the region nearest to your customers / prospective customers.


Select the OS Image option under Image and select CentOS as shown in image.

Instance Plan

Select the necessary hardware configuration.


Select the necessary period for the server.

Current Selected

Verify the options you selected in previous steps.

Click on Buy Now.


Pay for your order.

You should now receive the payment complete page as shown in below image.

Deploy Application on Simple Application Server

Create Password

You should see the CENTOS Server running.

Click on right top of server info and select details as shown in below image.

Now you should be able to see the Server Management Screen.

Select Connect under Server Maintainance.

Please note the server IP Address. You will need it very shortly.

Select Set Password.

Provide a password to the root account for your server.

If you do not have putty Installed get it from and install on your local machine.

You need the above software to access server terminal.

Open putty.

Add the server IP Address you noted earlier and choose Open.

A terminal window opens and shows login as:

Add root and press enter

Add password you set earlier for server

You are now ready to add commands to the terminal

Install Prerequisites on Server

yum is the primary tool for getting, installing, deleting, querying, and managing software packages in CentOS. First we use it to update software repository to the latest versions.

yum -y update


npm depends on Git, so we install Git

sudo yum install git

When it asks if this is OK[y/d/N]: y


cURL is the command line tool and library that is used for transferring data with URL syntax.

yum -y update
sudo yum install curl


Node.js depends on the EPEL repository being available.

To enable the EPEL repository

sudo yum install epel-release

Now, install Node.js

curl --silent --location | sudo bash -
sudo yum -y install nodejs

install build tools to compile and install native add-ons from the npm

sudo yum install gcc-c++ make

To verify if the Node.js installation was successful, issue the following command:

node -v

The output should be as shown in the following image

Deploy Application

git clone nodeexprss

Change to your directory with project code

cd nodeexprss

Install Node Packages

npm install

Start the application by running

npm start

We now need to Configure firewall such that requests to port 3000 are allowed.

Go back to the Server management screen and select the option Firewall under Security.

Click on button Add Rules and add a firewall rule as shown in image below.

Open a new browser window/tab and add server ip address and 3000 ( port number) in the format server_ip_address:port

Congratulations, you have successfully deployed your application on Alibaba Cloud Simple Application Server. You can also see requests in the terminal as in image below.

Final Steps

The server shows :

This site can't be reached refused to connect.

This shows that the Terminal close also shuts the Node.js application.

So, we need a method which will keep the Node.js application running even after Terminal close.

Also, one would require to enable a means such that users do not need to add the port number in the browser bar.

Open a new session in putty and login

To ensure users do not need to add port number on browser bar, redirect port 80 to port 3000 with this command:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

To ensure Node.js application continues to run after Terminal close, we use PM2, which is a process manager for Node.js applications and provides an easy way to manage and run them as a service.

To install PM2

sudo npm install pm2 -g

To start the application

cd nodeexprss
pm2 start app.js

You can use PM2 for quite a few other roles including monitoring as well as auto boot at server restart.

Now close your Terminal session and go to browser and add just your server address without the port number.

You should see your application running as shown in image below.


There are a lot of other things one has to do to get a production ready server starting from adding security features like firewall, disabling root access and creating other users to maybe using a nginx server as a reverse proxy. There are enough articles available on the web for the same and one would need to study them as well.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website: