Installing NodeJS Development Environment in Amazon AWS EC2

Amazon EC2 is a cloud-based hosting service that is free for 1 year for new customers. You can host your website, blog, any experiment project on a dedicated Linux box.

I have been looking for VPS hosting service to host my Node.js demos because shared hosting is still not providing this service. After all my research, Amazon ec2 is my choice.

In this post, I’ll take you through step by step configuration and installation of the Nodejs development environment in the Amazon EC2 Linux box.

NodeJS in Amazon EC2

If you are going to follow each step then completion will take around 30-40 minutes. We are going to cover following steps. If you have done any steps already, I suggest you to jump on the next one.

Step 1 : Create account at Amazon AWS

Go to Amazon EC2 page and create new account. They will ask you to provide billing information so make sure you have a supported credit card. They won’t charge you for first-year but billing after completion of the free year.

Step 2 : Launch EC2 instance

Login to AWS console. You should see a screen like below. Click on “EC2” in the “Compute” section.

Screen Shot 2015-05-17 at 1.20.57 PM

Click on Instances and then click on “Launch Instances”. This will take you to a setup wizard. The first step is choosing an Operating System for your EC2 instance. Choose anyone you are familiar with, I chose Amazon Linux.

Screen Shot 2015-05-17 at 1.29.06 PM

Next, you need to choose the Hardware configuration for your EC2 instance, this is a little technical and choices may vary depending on your need. I chose Intel Xeon 2.5 GHz 1 GB Ram Machine which is default and free for 1 Year.

Screen Shot 2015-05-17 at 1.30.35 PM

The next step is the configuration of the EC2 instance. Click on Next and you should see the storage configuration screen.

I chose default i.e 8 GB but in the free tier, you can use up to 30 GB storage. If you want more than that, then they will set up billing accordingly and charge from your credit card.

Screen Shot 2015-05-17 at 1.34.30 PM

The next step is tagging Instances which is not that important, you can skip it too. The next screen is important which is configuring the security group. In this, you need to allow HTTP port 80 for your web application.

Click on Add rule, choose type as HTTP and it will automatically assign port 80 to it.

Screen Shot 2015-05-17 at 1.38.17 PM

All right, this is it. Review your EC2 instance and click on launch. It will take few minutes to set up and you will see your Amazon EC2 running.

Screen Shot 2015-05-17 at 1.39.34 PM

One more thing. Once you click on launch, Amazon will ask you to create key pair which is very important. Select create new pair and give a name to your private key, once done click on “Download keypair” and Launch the instance.

Screen Shot 2015-05-17 at 1.41.24 PM

Download this key and store it somewhere, by using this you will be able to connect to your Linux box.

Click on Launch and you should see a similar screen like this in a minute.

Screen Shot 2015-05-17 at 1.44.18 PM

Congratulation! Your Amazon EC2 is up and running.

Connecting to your Amazon EC2 Linux box.

I hope you have downloaded your private key somewhere on your computer. Now if you are using Windows you might need to use Putty. I use Mac and I will show you how to connect using basic SSH using our private keypair. You can use SSH on a Linux machine too.

First of all, copy “Public DNS” from the instance screen shown in step 2. Open up your terminal and switch to the folder where you have downloaded the key file.

First set the access mode to this file to readable to you only else Amazon will not consider this file and gives you a message regarding public mode and threat to security. So run this command.

sudo chmod 400

Now to connect to your Amazon EC2 Linux box, run the following command in your Terminal.

sudo ssh -i  ec2-user@

For example:

sudo ssh -i sample.pem

Here is my screen.

Screen Shot 2015-05-17 at 1.55.56 PM

All right. You are now connected to your Amazon EC2 box. It’s time to install Node.js and NPM and run a simple Express server.

Installing Node.js and NPM on Amazon EC2

Switch to the home folder using following command.

cd /home/ec2-user/

First of all update the Amazon system using following command.

sudo yum update

This is going to take some time so be patient.
Screen Shot 2015-05-16 at 8.39.57 PM

Yum package manager has no direct node.js or node repository so you need to manually download and compile the node.js binary package. This step will take some time so make sure you grab a coffee before starting.

1: Install GCC++ and Make

sudo yum install gcc-c++ make

2: Install openssl-dev

sudo yum install openssl-devel

3: Install git

sudo yum install git

Execute these commands one by one and then run the following.

1: Download the latest version of Node.js

git clone git://

Switch to node folder.

cd node

In order to install Node.js, you need to switch to the latest branch of it. Current stable version at the time of writing this tutorial is v0.12.2.

Run this command to switch to branch.

git checkout v0.12.2

Run following commands one by one.



sudo make install

The above steps will take around 10-15 minutes to complete. Once done you should be able to use node.js in your Amazon EC2 system.

Install NPM

Before installing any node modules in your system we need to add a path where those modules should get installed. To do so, you need to edit sudoers file. Here is how to do so.

sudo su
vi /etc/sudoers

Once VI editor is open, find this line.

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Once found, press the “i” key to go in insert mode in VI, and at the end of this line add the following.


Or replace it with this.

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

In order to save your changes, press the ESC key and type “wq” and hit ENTER in VI editor.

All right, let’s install the NPM module.

1: Clone the NPM.

git clone

2: Install the NPM.

cd npm
sudo make install

Wait for few minutes and you are done!

Say “Hello World”

Congratulations! We have finally set up and installed the Amazon EC2 and Node.js. It’s time to test the setup. Let’s create one simple project and print “Hello World”.

Create a new folder and switch to that folder. create package.json using VI and paste this code.

"name": "sample",
"version": "0.0.1",
"dependencies": {
"express": "^4.12.3"


npm install

to install Express.

Create app.js file and paste following code.

var express = require("express");
var app = express();


Hello from EC2



Run this app using the following command.

sudo node app.js

Make sure you use SUDO for it. Visit your public DNS and you should see a screen like this.

Screen Shot 2015-05-17 at 2.29.08 PM


Amazon is one of the best cloud services provides and above all they let us try their System for free. You can use it to host your project, blog, website, or anything. We have covered almost everything you need to get started but there are still some configurations left like mapping domains to EC2 instances.

51 thoughts on “Installing NodeJS Development Environment in Amazon AWS EC2”

  1. Curious what path you should set your workspace or project in? Do you use the forever module for continuous deployment? Also how do we set domain to server IP address and port it? Also if we set up mongodb would it be wise to host on separate server or same one? How could we connect the two servers together if we did?


    1. That’s a good set of question.

      1: I have not set any path yet, should be /home/projects ?

      2: Yes i use forever.

      3: To setup it we need to launch Amazon S3 and map the name space to our domain. I did’t tried it yet.

      4: You can host Mongo on same server with port or if you got two server, better have it there.

      5: Allow the HTTP port in the second instance and call it via HTTP. Should’t trouble you.


  2. Great tutorial. A few suggestions for silly users like myself.

    Node and NPM seem to always have to be run with sudo. So I had to do “sudo npm install” to get express installed.

    Also when you make the directory that you put the json file in you want to do that as a sibling to the node folder.

    If I’m not mistaken the node and npm folders are just used to build node and npm for the box, but you don’t want to put anything in them.

  3. Thanks for your tutorial it’s very easy to follow. But there is a problem before installing npm when we have to modify the sudoers file. Even when using sudo su I still can’t modify the file, I got an error “W10: Warning: Changing a readonly file”

    1. You can change the permission of the file using `chmod 0775 /etc/sudoers`. After that you’ll be able to write to the file

  4. To exit the vi editore Esc and wq didn’t do.

    This cut from google helped:
    To quit the vi editor without saving any changes you’ve made:
    If you are currently in insert or append mode, press Esc .
    Press : (colon). The cursor should reappear at the lower left corner of the screen beside a colon prompt.
    Enter the following: q!

  5. so yea, you can do npm init to generate a package.json file, and then when you install modules make sure to add –save i.e. install express –save this will add module name to package.json

    1. Also if you’re installing node v6+ it comes with NPM, no need to install it separately. ๐Ÿ™‚

  6. Michael Warren

    I get the following error on trying to run it:

    [ec2-user@ip-172-31-46-64 SampleNodeProject]$ sudo node app.js
    throw er; // Unhandled ‘error’ event
    Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1146:14)
    at listen (net.js:1172:10)
    at Server.listen (net.js:1257:5)
    at EventEmitter.listen (/home/ec2-user/SampleNodeProject/node_modules/express/lib/application.js:617:24)
    at Object. (/home/ec2-user/SampleNodeProject/app.js:8:5)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

    Searching Google for answers failed. ๐Ÿ™

      1. I tried a different port, and am able to get the server running. However, when I visit the public DNS, I get the Apache test page instead.

          1. You need to pass the port number in URL to get to your node app page. Reason why you are getting apache one is because of request at port 80.

        1. Thank you for sharing the tips.

          You mind if i include this in tutorial ? Reason why i have’t done yet is because i had no domain to map while i was writing this tutorial.

  7. hi sahid ,
    i am having an issue with the nginx server and node.js app which is hosted by AWS , when i shifted my service from http to https (secure) it stopped on the same .actually i made the service api running but i’m not able to process the web app it still stucked at the same page the error is that nginx couldn’t find the public/js folder as it saved on the path .Please help me in resolving this.

  8. sudo apt-get install nodejs
    sudo apt-get install npm
    sudo ln -s /usr/bin/nodejs /usr/bin/node

    should work right !

    1. Shahid (UnixRoot) Shaikh

      Yes but ubuntu do not get updated frequently as the Github one. So you may not get latest version from Ubuntu repos right after the release of Node.js.

  9. I don’t know if I did something wrong following the steps but when I go to my public dns nothing is showing ” keeps telling me site cannot be reached “

      1. I’m having this issue, I can’t access when using CURL

        curl: (7) Failed to connect to port 80: Connection refused

    1. Shahid (UnixRoot) Shaikh

      Yes, you need to switch to a normal user.

      You can clone at location assuming there is no permission issue. My suggestion is to switch to /home folder and performing cloning and installation.

  10. Hi Shahid,

    I’m facing the below error when I tried NPM install after creating PACKAGE.JSON. I also faced some warning during NPM installation. Please suggest some solution to install NPM and comple node js deployment successfully

    throw err;
    Error: Cannot find module ‘proto-list’
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object. (/usr/local/lib/node_modules/npm/lib/utils/ini.js:38:17)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)

    1. Shahid (UnixRoot) Shaikh

      For which module it came ?

      Anyway, running npm install proto-list should work.

  11. Hi Shahid,

    I’m facing the below error while executing the command cd npm, sudo make install. Please support me to resolve the issue

    [root@ip-172-31-30-100 npm]# sudo make install
    scripts/ doc/cli/ man/man1/npm-access.1
    make[1]: Entering directory `/home/ec2-user/node/npm’
    node cli.js install marked-man –no-global
    bash: node: command not found
    make[1]: *** [node_modules/.bin/marked-man] Error 127
    make[1]: Leaving directory `/home/ec2-user/node/npm’
    make: *** [man/man1/npm-access.1] Error 2

    1. Mauricio Montalvo

      Hi Shahid,

      I had the same problem, the issue is that node is not globally installed, it’s only in your node/ folder.

      So, in order to fix that, you should go to you node/ folder and run the following command:

      ln -fs out/Release/node /usr/local/bin/node

      this commands creates a symbolic link in your user bin folder yo expose the node command.

      I hope it will be helpful for you ๐Ÿ™‚

  12. Isn’t npm already included as part of node v0.12.2? Should it be cloned from github and reinstalled again?

  13. very good tutorial for Amazon service .Thank you for sharing that kind of wonderful knowledge,
    please share this thing with Docker and Ngnix server.

  14. Hi there,
    Great tutorial. I ended up with node and npm command cannot be found.
    the extra line fixed it for me:
    export PATH=$PATH:/usr/local/bin

    thank u ๐Ÿ™‚

  15. Hi Shahid,
    Thanks for the great tutorial. I was able to launch the app, install node and npm and run the server on my terminal but I didn’t get any response when I hit my public DNS in the browser. Is there some setup that we need to tweak in the AWS account?

  16. Good tutoril,
    Can you please tell me how to open and enter code into app.js file.
    I created package.json and app.js file but how can I enter code into app.js.

    Thank you.

    1. I had one more problem,
      How can i connect with mysql and node in ec2.
      In my local host, i connected perfectly with mysql of S3 and node.js. But when I put the same code into AWS instance then it gives “time out error”.
      Can you have any solution for this problem.

  17. Hi, I was doing with Vue js on amazon Linux. The server started up with localhost:8080.
    But it is not coming up when I try with public DNS.
    HTTP port is also open on EC2.
    Still, it is failing.

Comments are closed.