HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to Setup Node and Express on Amazon Web Services EC2

113,143 views October 31, 2014 31:30

Watch on YouTube
ChannelMicrowaveSam

Description from the creator

How to Setup Node and Express on Amazon Web Services EC2

1) Make an account on Amazon Web Services
aws.amazon.com/

2) Create a vanilla Ubuntu micro EC2 instance

3) Security
Open HTTP, HTTPS, Port 8080, and Port 9000

4) Launch the instance and save the pem file (private key)

5) Make sure that pem file has correct permissions
chown :Users node.pem
chmod 600 node.pem

5) Update Ubuntu and install these packages
sudo apt-get update
sudo apt-get install libssl-dev g++ make

6) nodejs.org/download/
(Get node source files)
wget nodejs.org/dist/v0.10.32/node-v0.10.32.tar.gz

7) Extract the packed tar.gz and change directory
tar -xvf node-v0.10.32.tar.gz
cd node-v0.10.32

8) Execute the binaries, make, and install
./configure && make && sudo make install

9) cd ../
mkdir test1
cd test1
vim test1.js

(Insert is to edit as esc :x is to save)

10) var http = require('http');

var port = 9000;

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello there, world!\n');
}).listen(port);

console.log('Listening on port', port);

11) node test1.js (to run the javascript file on node)
CTRL+C to exit command
nohup node test1.js & (to run as a background process - no hiccup)
ps -ef (to check all background processes)
kill id_number

12) cd /home/ubuntu
sudo npm install express

13) mkdir test2
vim test2.js

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

app.get('/', function (req, res){
res.send('Hello there, world!\n');
});

var port = 9000;
app.listen(port);
console.log('Listening on port', port);

14) Reroute IP Tables so that javascript file also displays on port 80

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

Twitter: twitter.com/microwavesam

About this tutorial

MicrowaveSam published this 31:30 video tutorial on October 31, 2014. It has been watched 113,143 times on YouTube.

Duration
31:30
Published
October 31, 2014
Views
113,143
Likes
1,361

Tags

Share

This tutorial in other languages