This document provides steps for deploying a Node.js application without getting fired, from initial setup through scaling. It begins with installing Node.js on a VPS or virtual private server. Basic steps include initializing version control with Git, adding logging and error handling, and using Upstart to ensure the app runs at boot and respawns if it crashes. Advanced techniques include using multiple processes, a cache like Varnish, staging environments, and eventually multiple app servers with the database on separate boxes controlled by tools like node-control. The document emphasizes automating deployments and scaling gradually over time.
44. Varnish Cache
• avoid repeating work
• set headers and go
sudo apt-get install varnish
sudo vim /etc/default/varnish # port 80
sudo vim /etc/varnish/default.vcl # point to our app at port 3333
sudo /etc/init.d/varnish start
51. > npm install express
...
> ls
app.js node_modules
> node app.js
Listening on 3333
Editor's Notes
quick intro to topic\n
long-time consultant\nCofounder of i.TV\n
make TV amazing. \ncool announcements\nused node in production for 2 years. STORY. We picked it because we thought it was cool.\n\n
this is going to be a walk-through\ninterrupt me\n
front-end developers?\ngotten a node app working on your computer?\ndeployed a node or ruby app to production by hand before?\n\n
WALKTHROUGH. \nfollow a company. some of the steps are wrong, but we will explain why and show how to correct them.\nWe’re going to follow the story of a budding young entreprenuer\nBegin the story: local js meetup. talk on semicolons\n\n
\n
\n
because you know and like javascript, and you heard it scales\nDOES have a big advantage: JS Skills\n
All the real companies use .NET\nAfter a 3 hour meeting with your partner, you finally convince him to leave the decision to you and head out to learn. \n
\n
you don’t make a new one each time a requests. Only will work if it’s on and plugged in, ready to go. Listens on a socket. Different than PHP.\nIf we Control-C the program stops. \n
\n
* we’ll show off some cool stuff later\n
nice thing is they are all the same, so you can jump between providers depending on cost\n
domain name? (hosts file)\nSet up the server, and show how to log in. \nSwitch to VM?\n\n
\n
\n
\n
\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
Add a non-root user\ninstall nodejs (source: google)\n
get it running online\n
\n
demo it!\neven if you run it in the background\n
DEMO!\n
The “boss” makes you tell him how to edit the app. He breaks it. \n
Demo using git to deploy. (checkout, public)\ngit clone git://github.com/seanhess/ratinatorly.git\n
intro to npm\nshow how to deploy without copying node_modules\nuse npm init\nexpress: \n
\n
\n
\n
tell the story\n
\n
DEMO init script\nDEMO deploying with init script\n
montastic.com\n
when it crashes\nuncaught exception\nlogs\n
DEMO redirect with upstart\nDEMO track down the bug\nCan add fancy log analysis later\n
DEMO: show the uncaughtException code\n
\n
\n
DEMO: bash automated deploy\nNOPASSWD in sudoers (sudo visudo)\nsave fancier stuff for later when you have multiple servers (node-control, capistrano)\n
\n
DEMO: paste in the cluster code from the real one and check it closely\n\nvar os = require('os')\nvar cluster = require('cluster')\nif (cluster.isMaster) {\n\n for (var i = 0; i < os.cpus().length; i++) {\n cluster.fork()\n }\n}\nelse {\n app.listen(3333)\n console.log("Listening on 3333")\n}\n\n
DEMO\nsudo apt-get install varnish\nsudo vim /etc/default/varnish\nsudo vim /etc/varnish/default.vcl\nsudo /etc/init.d/varnish start\n\n
\n
heroku create --stack cedar\ngit push heroku master\nchange the port! (check the logs)\n