32
Intro to the MEAN Stack Valeri Karpov Kernel Tools Engineer, MongoDB thecodebarbarian.com github.com/vkarpov15 @code_barbarian Using NodeJS to drive superheroic web apps

NodeSummit - MEAN Stack

Embed Size (px)

DESCRIPTION

Valeri Karpov's talk about the MEAN stack at NodeSummit on 12/3/13

Citation preview

Page 1: NodeSummit - MEAN Stack

Intro to the MEAN Stack

Valeri KarpovKernel Tools Engineer, MongoDB

thecodebarbarian.comgithub.com/vkarpov15

@code_barbarian

Using NodeJS to drive superheroic web apps

Page 2: NodeSummit - MEAN Stack

Who is this guy?

CTO 2008

Page 3: NodeSummit - MEAN Stack

What does MEAN mean?

MongoDB - document database

ExpressJS - web framework for NodeJS

AngularJS - client MVVM, server ⇔ UX

NodeJS - event-driven IO in Javascript

Page 4: NodeSummit - MEAN Stack

What is this talk about?- Building a new web app: its easy…- … except when it isn’t

Expectation Reality

Page 5: NodeSummit - MEAN Stack

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

Page 6: NodeSummit - MEAN Stack

Prototype“Done is better than perfect.”

- Facebook developer mantra

Page 7: NodeSummit - MEAN Stack

Prototype- Goal: Get usable product in users’ hands fast

- Success story: Ascot Project

Page 8: NodeSummit - MEAN Stack

Prototype- Surface: one language makes life easier

- Surface: package management

- Deeper: tight binding from database to client

Page 9: NodeSummit - MEAN Stack

Start with a UI Interactive client-side templating

Client-side: JSON bound to state of view

Page 10: NodeSummit - MEAN Stack

Server View of Data Interactive client-side templating

Server receives JSON data as-is

Page 11: NodeSummit - MEAN Stack

Database View of Data Interactive client-side templating

MongoDB stores JSON data as-is

Page 12: NodeSummit - MEAN Stack

Why is this useful?- Lower barrier to entry for new devs

- Declarative UX

- Easier debugging

- Code reuse

Page 13: NodeSummit - MEAN Stack

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

Page 14: NodeSummit - MEAN Stack

Adapt- Application always starts out simple, but...

- REST APIs. Socket APIs. SMTP.

- How will you integrate with new tech?

Page 15: NodeSummit - MEAN Stack

The NodeJS Advantage- Threads and locks are difficult

- Cron jobs are difficult

- Your server needs to be concurrent

- NodeJS provides easy, testable concurrency

Page 16: NodeSummit - MEAN Stack

Best Case Scenario- Bitcoin arbitrage from apartment

- 1 hour from nothing to live trading

- 15 minutes to add a new exchange

Page 17: NodeSummit - MEAN Stack

Test“Beware of bugs in the above code; I have only proved it correct, not tried it.”

- Donald Knuth, former Stanford CS Professor

Page 18: NodeSummit - MEAN Stack

The ChallengeHow do you prove your code works?

Success story: Bookalokal

Page 19: NodeSummit - MEAN Stack

The Evolution of Testing- Manual testing?

- Unit tests?

- E2E tests?

- Test runners?

- Continuous Integration.

Page 20: NodeSummit - MEAN Stack

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

Page 21: NodeSummit - MEAN Stack

MEAN Stack Advantage- E2E tests: angular-scenario

Page 22: NodeSummit - MEAN Stack

Karma test-runner- http://karma-runner.github.io

- Launch browsers, run tests on file save

- Compatibility: angular-scenario, nodeunit, jasmine

Page 23: NodeSummit - MEAN Stack

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

Page 24: NodeSummit - MEAN Stack

Scale“Go Big or Go Extinct”

- Tagline to the 2013 film Pacific Rim

Page 25: NodeSummit - MEAN Stack

A Word of Caution...Scalability is (mostly) a Maserati Problem

http://bit.ly/17gOvUO (Moderately NSFW)

Page 26: NodeSummit - MEAN Stack

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

Page 27: NodeSummit - MEAN Stack

What are the key points?- Don’t be Schlemiel the Painter

Page 28: NodeSummit - MEAN Stack

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.

Page 29: NodeSummit - MEAN Stack

Hard drive is slow- Especially true on EC2 - not an actual HD!

- Is your database reading from HD?

- MongoDB: In-memory “caching” built in! :)

Page 30: NodeSummit - MEAN Stack

Don’t choke the CPU- Is your server single-threaded?

- NodeJS: You get this for free! :)

Page 31: NodeSummit - MEAN Stack

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

Page 32: NodeSummit - MEAN Stack

Thanks for Listening!Comments, questions, haikus?

Read more at:thecodebarbarian.comgithub.com/vkarpov15

@code_barbarian