1. Intro to the MEAN Stack
Using NodeJS to drive superheroic web apps
Valeri Karpov
Kernel Tools Engineer, MongoDB
thecodebarbarian.com
github.com/vkarpov15
@code_barbarian
3. What does MEAN mean?
MongoDB - document database
ExpressJS - web framework for NodeJS
AngularJS - client MVVM, server ⇔ UX
NodeJS - event-driven IO in Javascript
4. What is this talk about?
- Building a new web app: its easy…
- … except when it isn’t
Expectation
Reality
5. The Problem Categories
Your 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
7. Prototype
- Goal: Get usable product in users’ hands fast
- Success story: Ascot Project
8. Prototype
- Surface: one language makes life easier
- Surface: package management
- Deeper: tight binding from database to client
9. Start with a UI
Interactive client-side templating
Client-side: JSON bound to state of view
10. Server View of Data
Interactive client-side templating
Server receives JSON data as-is
11. Database View of Data
Interactive client-side templating
MongoDB stores JSON data as-is
12. Why is this useful?
- Lower barrier to entry for new devs
- Declarative UX
- Easier debugging
- Code reuse
13. 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
14. Adapt
- Application always starts out simple, but...
- REST APIs. Socket APIs. SMTP.
- How will you integrate with new tech?
15. The NodeJS Advantage
- Threads and locks are difficult
- Cron jobs are difficult
- Your server needs to be concurrent
- NodeJS provides easy, testable concurrency
16. Best Case Scenario
- Bitcoin arbitrage from apartment
- 1 hour from nothing to live trading
- 15 minutes to add a new exchange
17. Test
“Beware of bugs in the above code; I have only
proved it correct, not tried it.”
- Donald Knuth, former Stanford CS Professor
19. The Evolution of Testing
- Manual testing?
- Unit tests?
- E2E tests?
- Test runners?
- Continuous Integration.
20. 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
23. 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
24. Scale
“Go Big or Go Extinct”
- Tagline to the 2013 film Pacific Rim
25. A Word of Caution...
Scalability is (mostly) a Maserati Problem
http://bit.ly/17gOvUO (Moderately NSFW)
26. 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
27. What are the key points?
- Don’t be Schlemiel the Painter
28. 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.
29. Hard drive is slow
- Especially true on EC2 - not an actual HD!
- Is your database reading from HD?
- MongoDB: In-memory “caching” built in! :)
30. Don’t choke the CPU
- Is your server single-threaded?
- NodeJS: You get this for free! :)
31. A Common Criticism
Will 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