how to deploy node to production
DESCRIPTION
TRANSCRIPT
![Page 1: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/1.jpg)
HOW TO DEPLOY NODEwithout getting fired
![Page 2: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/2.jpg)
@seanhess
seanhess.github.com
![Page 3: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/3.jpg)
![Page 4: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/4.jpg)
Try it yourself
deploynode.tkpublicpublic
userpass
![Page 5: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/5.jpg)
WHOARE
YOU?
![Page 6: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/6.jpg)
from FIRST STEPSto MISSTEPS
toSCALE
![Page 7: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/7.jpg)
Ratinatorlywho RATES the RATE-MEN?
![Page 8: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/8.jpg)
100,000
SALARY is for chumps
shares of sweat-equity
![Page 9: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/9.jpg)
you decide to try
![Page 10: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/10.jpg)
Your First Node“but my brother says that .NET is the best
language”
![Page 11: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/11.jpg)
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")
![Page 12: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/12.jpg)
your app is aLONG RUNNINGPROCESS
it handles all the requests...if it’s on
![Page 13: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/13.jpg)
“Sequoia is going to LOVE this”
PROTOTYPEthemust be ONLINE
![Page 14: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/14.jpg)
FAIL SHARED HOSTING
PROGRAMyou need to run a
*
![Page 15: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/15.jpg)
WIN!VPSlike a cheap
DEDICATED SERVER
![Page 16: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/16.jpg)
sudo make me a serverokay...
![Page 17: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/17.jpg)
![Page 18: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/18.jpg)
![Page 19: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/19.jpg)
![Page 20: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/20.jpg)
![Page 21: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/21.jpg)
> ssh [email protected]@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
![Page 22: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/22.jpg)
• copy our code
• node app.js
MAKE IT GO
![Page 23: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/23.jpg)
“I didn’t do anything... Check Energy Saver”
DON’Tthe
CLOSELID!!
![Page 24: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/24.jpg)
your BELONGSto your
ssh session
DIELOG OUT ==
app
![Page 25: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/25.jpg)
LOGGED INkeeps you
SCREEN
![Page 26: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/26.jpg)
Undo! Rollback!“I know enough HTML to be
dangerous”
your boss tries to deploy
![Page 27: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/27.jpg)
let’s add
use GIT to deploy
VERSION CONTROL
![Page 28: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/28.jpg)
package.jsonDEPENDENCIESmanage your
> npm install
![Page 29: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/29.jpg)
a PROCESS emerges• git commit and push
• log in to server
• pull
• npm install
• restart
![Page 30: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/30.jpg)
“I’ve got Techcrunch right where I want them”
LAUNCH!
![Page 31: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/31.jpg)
port 80
•must run as root
![Page 32: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/32.jpg)
This is where I stop trying to design my slides
![Page 33: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/33.jpg)
It keeps DYING!
“Maybe we should try windows servers instead”
![Page 34: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/34.jpg)
upstart
•OS will start on boot
•Respawn
![Page 35: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/35.jpg)
monitoring
•know if it goes down
![Page 36: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/36.jpg)
It works for me!or, when the cracks first
began to show...
![Page 37: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/37.jpg)
logging
• keep your output
![Page 38: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/38.jpg)
uncaughtExceptionprocess.on(“uncaughtException”, function(err) {
console.log(err.message)})
![Page 39: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/39.jpg)
Don’t forget step 6!
“Will you put my changes up for me?”
![Page 40: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/40.jpg)
complicated deploy
• it can get easy to miss a step
![Page 41: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/41.jpg)
automated• keep the knowledge in your code
base
• put extra stuff in package.json “install”
![Page 42: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/42.jpg)
Too Slow!“Let’s just throw more
money at this"
![Page 43: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/43.jpg)
Multiple Processes
• cluster up to your cores
![Page 44: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/44.jpg)
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
![Page 45: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/45.jpg)
Staging Box
![Page 46: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/46.jpg)
cheat with Heroku
• it’s easy, but can be expensive
![Page 47: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/47.jpg)
Scale“We should aim for... 100
million users”
![Page 48: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/48.jpg)
Multiple Servers• more app servers
• varnish and db on separate box
• use node-control to deploy
• smart db = good for a long time
![Page 49: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/49.jpg)
automateandUPSTART GIT
or CHEATwithHEROKU
rememberwith
![Page 50: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/50.jpg)
@seanhessseanhess.github.com
![Page 51: How to deploy node to production](https://reader033.vdocument.in/reader033/viewer/2022050808/54822ad0b07959490c8b4729/html5/thumbnails/51.jpg)
> npm install express...> lsapp.js node_modules> node app.js Listening on 3333