Deploy app on server

In this section, you will get to know how to deploy your Node.js application on Amazon Web Service.

There’re two ways to install Node.js on Ubuntu and other Linux distributions:

  1. Compile and install from the source of Node.js
  2. Using package management tool (like apt-get and yum) of the Operating System: instruction on Github), and I chose this approach:
  1. curl -sL | sudo bash -
  2. sudo apt-get install nodejs

Then you could use VIM to edit a simple JavaScript file to have a test on your server:

  1. console.log('Hello Node.js and AWS.');


Firstly, I should clone the repository on Github:

  1. git clone

Then install the dependencies:

  1. npm install

For we run the App using supervisor during the developing period, it’s better to choose PM2 to run it on EC2.

Install PM2: sudo npm install -g pm2

Edit the “scripts” field on package.json

  1. pm2 start ./bin/www

Now we are able to start our application using npm start command.


It’s very simple to install Nginx on Ubuntu:

  1. sudo apt-get install nginx

Nginx has been started when the installation completed. If we visit the public IP of EC2, the below is what we can see:


And now, we have to modify the config file of Nginx to make the proxy work.

The default config file is at /etc/nginx/nginx.conf

  1. upstream riki {
  2. server;
  3. }
  4. server {
  5. listen 80;
  6. server_name localhost;
  7. location /{
  8. proxy_pass http://riki;
  9. }
  10. }

And now we can visit Riki via IP without :3000: