INTOTHE WILD WITH
NODE.JS AND WEB APPS
Node.jsTalk at Klout, 2012
Chris Bumgardner
Friday, April 20, 12
ME
• Co-founder and Chief-Programmer of AskYourUsers.com
• @chrisbumgardner and cbumgard@gmail.com
• github.com/cbumgard
•...
THE STACK
• Node.js
• Express
• MongoDB
• Redis
• Apache Solr
• Nginx / Ubuntu 11 / 2 x LinodeVPS
Friday, April 20, 12
CONFIGURATION
• Partition your configuration by environment.
• E.g. Config[process.env.NODE_ENV]
• We have 3 environments: 2...
CONFIGURATION 2
• dev env 1: sessions in memory, clean db each start.
• dev env 2: persistent sessions & db, ssl.
• produc...
LOGGING
• Log early and often.
• Using Winston with the MongoDB transport.
• MongoDB logging: fast writes; pass json objs ...
DEPLOYMENT
• Custom CI system in node that responds pushes to github
• Post-Receive service hook. Github POSTs to us after...
ALSO
• In development: use ‘nodemon’ to start server.
• Watches all files in project and restarts node if anything
changes....
CLUSTERING
• In production, use ‘cluster’ module to fork separate node per
core
• App-wide initialization: if cluster.isMa...
DEPENDENCIES
• Found out the hard way to control node, npm, and dependent
module versions.You don’t want to push a change ...
PROFILING
• ‘ab’ is your friend.
• don’t forget ulimit.
• Joyent has great video on profiling with dtrace.
• ‘nodetime’ mod...
THANKS!
(you can email me at cbumgard@gmail.com)
Beyond the Closed Beta, Node.js from code to
production (at scale)
Node.j...
Upcoming SlideShare
Loading in...5
×

Into the Wild with Node.js and Web Apps

292

Published on

Node.js Presentation at Klout HQ, 2012
By Chris Bumgardner @ "Beyond the Closed Beta, Node.js from code to production (at scale)"

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
292
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Into the Wild with Node.js and Web Apps

  1. 1. INTOTHE WILD WITH NODE.JS AND WEB APPS Node.jsTalk at Klout, 2012 Chris Bumgardner Friday, April 20, 12
  2. 2. ME • Co-founder and Chief-Programmer of AskYourUsers.com • @chrisbumgardner and cbumgard@gmail.com • github.com/cbumgard • My first ‘real’ production web app in Node.js • Invite only beta, going live this week. Friday, April 20, 12
  3. 3. THE STACK • Node.js • Express • MongoDB • Redis • Apache Solr • Nginx / Ubuntu 11 / 2 x LinodeVPS Friday, April 20, 12
  4. 4. CONFIGURATION • Partition your configuration by environment. • E.g. Config[process.env.NODE_ENV] • We have 3 environments: 2 dev and 1 production. • Environment is top-level namespace (‘dev’,‘production’, etc) for everything, including db. Keeps worlds from colliding. • Makes life easy Friday, April 20, 12
  5. 5. CONFIGURATION 2 • dev env 1: sessions in memory, clean db each start. • dev env 2: persistent sessions & db, ssl. • production env: aggressive caching, ssl, live payments, clustered, fancier logging (more later), email/sms notifications. Friday, April 20, 12
  6. 6. LOGGING • Log early and often. • Using Winston with the MongoDB transport. • MongoDB logging: fast writes; pass json objs in log msgs; easy ad-hoc queries; easy lru via capped collections. • Client logging from browser: caught and logged to Google Analytics as custom event. Easy monitoring/aggregation. Friday, April 20, 12
  7. 7. DEPLOYMENT • Custom CI system in node that responds pushes to github • Post-Receive service hook. Github POSTs to us after a push. • CI will pull code if it’s the right branch (say ‘staging’), restart, and send SMS. • Easy and low touch.Texts from your node are nice. • Refactoring into a more modular/decoupled hook.io system. Friday, April 20, 12
  8. 8. ALSO • In development: use ‘nodemon’ to start server. • Watches all files in project and restarts node if anything changes. • Great with persistent sessions, test changes immediately. • In production: use ‘forever’ to start server as daemon. Restarts node automatically if it crashes. Runs in background. Nice CLI. Manages stdout/stderr logs.Tracks multiple processes. Friday, April 20, 12
  9. 9. CLUSTERING • In production, use ‘cluster’ module to fork separate node per core • App-wide initialization: if cluster.isMaster • Otherwise per-proc initialization Friday, April 20, 12
  10. 10. DEPENDENCIES • Found out the hard way to control node, npm, and dependent module versions.You don’t want to push a change to production and have npm barf. No bueno. • Keep them the same on all machines. • Use npm in development. • In production I recommend bundling/controlling the deps and versions explicitly. Friday, April 20, 12
  11. 11. PROFILING • ‘ab’ is your friend. • don’t forget ulimit. • Joyent has great video on profiling with dtrace. • ‘nodetime’ module: great in development, but my server got hosed when I tried it in production. Probably user error. Friday, April 20, 12
  12. 12. THANKS! (you can email me at cbumgard@gmail.com) Beyond the Closed Beta, Node.js from code to production (at scale) Node.js ++ (Serverside Javascripters) Club SF Friday, April 20, 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×