nodesummit - mean stack
DESCRIPTION
Valeri Karpov's talk about the MEAN stack at NodeSummit on 12/3/13TRANSCRIPT
Intro to the MEAN Stack
Valeri KarpovKernel Tools Engineer, MongoDB
thecodebarbarian.comgithub.com/vkarpov15
@code_barbarian
Using NodeJS to drive superheroic web apps
Who is this guy?
CTO 2008
What does MEAN mean?
MongoDB - document database
ExpressJS - web framework for NodeJS
AngularJS - client MVVM, server ⇔ UX
NodeJS - event-driven IO in Javascript
What is this talk about?- Building a new web app: its easy…- … except when it isn’t
Expectation Reality
The Problem CategoriesYour problems look something like this:
Prototype. Build a usable product fast
Adapt. Iterate on feedback
Test. Automate testing using CI
Scale. Utilize server resources efficiently
Prototype“Done is better than perfect.”
- Facebook developer mantra
Prototype- Goal: Get usable product in users’ hands fast
- Success story: Ascot Project
Prototype- Surface: one language makes life easier
- Surface: package management
- Deeper: tight binding from database to client
Start with a UI Interactive client-side templating
Client-side: JSON bound to state of view
Server View of Data Interactive client-side templating
Server receives JSON data as-is
Database View of Data Interactive client-side templating
MongoDB stores JSON data as-is
Why is this useful?- Lower barrier to entry for new devs
- Declarative UX
- Easier debugging
- Code reuse
Adapt“There's a plaque on our wall that says we've sold over 65 million albums, and I don't feel I've accomplished anything. I feel like I'm just getting started.”
- Eddie Van Halen
Adapt- Application always starts out simple, but...
- REST APIs. Socket APIs. SMTP.
- How will you integrate with new tech?
The NodeJS Advantage- Threads and locks are difficult
- Cron jobs are difficult
- Your server needs to be concurrent
- NodeJS provides easy, testable concurrency
Best Case Scenario- Bitcoin arbitrage from apartment
- 1 hour from nothing to live trading
- 15 minutes to add a new exchange
Test“Beware of bugs in the above code; I have only proved it correct, not tried it.”
- Donald Knuth, former Stanford CS Professor
The ChallengeHow do you prove your code works?
Success story: Bookalokal
The Evolution of Testing- Manual testing?
- Unit tests?
- E2E tests?
- Test runners?
- Continuous Integration.
MEAN Stack Advantage- Javascript makes unit testing very easy
- Trivial dependency injection:
- AngularJS has built-in DI
- Lots of NodeJS DI, recommend
https://npmjs.org/package/omni-di
MEAN Stack Advantage- E2E tests: angular-scenario
Karma test-runner- http://karma-runner.github.io
- Launch browsers, run tests on file save
- Compatibility: angular-scenario, nodeunit, jasmine
Karma and CI- Jenkins: http://bit.ly/1fVqoC9
- Circle CI: http://bit.ly/1dhuR4A
- Travis CI: http://bit.ly/I3ojbF
- Semaphore: http://bit.ly/IgiWFz
Scale“Go Big or Go Extinct”
- Tagline to the 2013 film Pacific Rim
A Word of Caution...Scalability is (mostly) a Maserati Problem
http://bit.ly/17gOvUO (Moderately NSFW)
Scale… to what?- Difficult to judge exact number, say O(1000)
- Single machine
- 20% of mistakes 80% of new apps make
- Horror story: SCNVGR, 10/18/08
What are the key points?- Don’t be Schlemiel the Painter
Bandwidth is scarce- Is the browser caching static assets?
- Is your CSS and JS minified?
- Grunt everybody’s favorite minifier
- Bonus minify css/js on server start using uglify-js.
Hard drive is slow- Especially true on EC2 - not an actual HD!
- Is your database reading from HD?
- MongoDB: In-memory “caching” built in! :)
Don’t choke the CPU- Is your server single-threaded?
- NodeJS: You get this for free! :)
A Common CriticismWill MEAN be obsolete in 5 years? I hope so.
“To know ten thousand things, know one thing well.”
- The Book of Five Rings by Miyamoto Musashi
Thanks for Listening!Comments, questions, haikus?
Read more at:thecodebarbarian.comgithub.com/vkarpov15
@code_barbarian