How to deploy node to production

Post on 05-Dec-2014

14.251 views 2 download

description

 

Transcript of How to deploy node to production

HOW TO DEPLOY NODEwithout getting fired

@seanhess

seanhess.github.com

WHOARE

YOU?

from FIRST STEPSto MISSTEPS

toSCALE

Ratinatorlywho RATES the RATE-MEN?

100,000

SALARY is for chumps

shares of sweat-equity

you decide to try

Your First Node“but my brother says that .NET is the best

language”

var express = require('express')var app = express.createServer()

app.get('/', function(req, res) { res.send("Hello World!")})

app.listen(3333)console.log("Listening on 3333")

your app is aLONG RUNNINGPROCESS

it handles all the requests...if it’s on

“Sequoia is going to LOVE this”

PROTOTYPEthemust be ONLINE

FAIL SHARED HOSTING

PROGRAMyou need to run a

*

WIN!VPSlike a cheap

DEDICATED SERVER

sudo make me a serverokay...

> ssh root@ratinator.lyroot@ratinatorly's password:Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-virtual

# adduser node# adduser node sudo

# sudo apt-get install python-software-properties# sudo apt-add-repository ppa:chris-lea/node.js# sudo apt-get update# sudo apt-get install nodejs npm

• copy our code

• node app.js

MAKE IT GO

“I didn’t do anything... Check Energy Saver”

DON’Tthe

CLOSELID!!

your BELONGSto your

ssh session

DIELOG OUT ==

app

LOGGED INkeeps you

SCREEN

Undo! Rollback!“I know enough HTML to be

dangerous”

your boss tries to deploy

let’s add

use GIT to deploy

VERSION CONTROL

package.jsonDEPENDENCIESmanage your

> npm install

a PROCESS emerges• git commit and push

• log in to server

• pull

• npm install

• restart

“I’ve got Techcrunch right where I want them”

LAUNCH!

port 80

•must run as root

This is where I stop trying to design my slides

It keeps DYING!

“Maybe we should try windows servers instead”

upstart

•OS will start on boot

•Respawn

monitoring

•know if it goes down

It works for me!or, when the cracks first

began to show...

logging

• keep your output

uncaughtExceptionprocess.on(“uncaughtException”, function(err) {

console.log(err.message)})

Don’t forget step 6!

“Will you put my changes up for me?”

complicated deploy

• it can get easy to miss a step

automated• keep the knowledge in your code

base

• put extra stuff in package.json “install”

Too Slow!“Let’s just throw more

money at this"

Multiple Processes

• cluster up to your cores

Varnish Cache

• avoid repeating work

• set headers and go

sudo apt-get install varnishsudo vim /etc/default/varnish # port 80sudo vim /etc/varnish/default.vcl # point to our app at port 3333sudo /etc/init.d/varnish start

Staging Box

cheat with Heroku

• it’s easy, but can be expensive

Scale“We should aim for... 100

million users”

Multiple Servers• more app servers

• varnish and db on separate box

• use node-control to deploy

• smart db = good for a long time

automateandUPSTART GIT

or CHEATwithHEROKU

rememberwith

@seanhessseanhess.github.com

> npm install express...> lsapp.js node_modules> node app.js Listening on 3333