SlideShare una empresa de Scribd logo
1 de 124
Descargar para leer sin conexión
Guided MEAN Stack Hackathon 
Building (and Testing) a Single Page App in 2 Hours 
Valeri Karpov 
Software Engineer, MongoDB 
www.thecodebarbarian.com 
www.slideshare.net/vkarpov15 
github.com/vkarpov15 
@code_barbarian
Who is this guy? 
•Coined the MEAN stack in April ‘13 
•CI/Tools/NodeJS/Go Engineer at MongoDB 
•Maintains mongoose, omni-di 
•AngularJS since 0.9.4 in 2010 
•Hackmaster General at Bookalokal 
•Former CTO, LevelUp 
*
General Outline 
•MEAN = MongoDB, ExpressJS, AngularJS, NodeJS 
•Beginner talk: high-level concepts of MEAN 
•Emphasis on testing and workflow 
•Building a single page app - Axl 
•NPM-inspired Package Manager for Golang 
•Browser interface only 
•No Go knowledge required 
*
What You’re Building 
*
What You’re Building 
•Server for semver-aware package manager 
*
Concepts You’ll Be Learning About 
•Streams 
•API testing 
•DOM integration tests with Sauce 
•Build systems and architecture 
•Configuration + workflow 
•General principles for writing NPM packages 
*
NPM Packages You’ll Be Using 
•mocha: unit tests and API integration tests 
•browserify: compile Node JS into browser JS 
•mongoose: schema validation for Node + MongoDB 
•karma: browser automation for testing 
•gulp: general-purpose build workflow 
•And several more 
*
Step By Step, the Server Side 
•Step 1: Define the problem + brief overview of Go 
•Step 2: Define schema and models (mongoose) 
•Step 3: Build an API (express) 
•Step 4: API-level testing (mocha) 
•Step 5: Extending the API to support search 
*
Step By Step, the HTML Client Side 
•Step 6: Create AngularJS SPA client (browserify) 
•Step 7: Testing the Single Page App (karma) 
•Step 8: CDN for templates and JS (gulp) 
*
Step 1: A Brief Overview of Go 
•Language developed by Google 
•Cute toy language with some niche use cases: 
* 
• Fast-compiling small native binaries 
• Tight integration with C 
• “Agent” programs like MongoDB MMS agents 
•Has some bad limitations 
• Generics 
• Package management
Hello, World in Go 
*
Why Build a Go Package Manager 
•npm gets package management mostly right 
•Go doesn’t and could use some help 
*
What npm Does Right 
•Mostly semantic versioning (no v20130722) 
* 
• Will my code break if I upgrade from v2.1.3 to v2.1.4? 
•2 commands to install and test 
• npm install 
• npm test 
• And you’re ready to hack 
•No need to change PATH or env variables 
•Result: a package for every use case 
•Go doesn’t have any of this
Goals for Axl Server 
•Upload/download releases of projects 
•Projects hosted on Amazon Cloudfront (streams!) 
•Query for projects using semver syntax: 
* 
• version 1.2.0 matches “~1.2”, “>=1.2.0”, “<=1.3.0”, etc. 
• Thankfully, there’s an npm module for that 
•Ability to search projects by keyword 
•Sane build system and workflow 
•Take advantage of a single page app
Step 2: Design Schemas 
“Smart data structures and dumb code works a lot better 
than the other way around.” 
* 
- Eric S. Raymond 
“Bad programmers worry about the code. Good 
programmers worry about data structures and their 
relationships.” 
- Linus Torvalds
A Brief Overview of Mongoose 
•MongoDB is schema-less 
•But your schema design still matters! 
•Mongoose = NodeJS schemas for MongoDB 
* 
• Validation 
• Casting for objects and queries 
• Promises and other syntactic sugar 
• Object document mapper (ODM) 
•Users include Tinder and McDonalds
Simple Example: A User Schema 
*
Model = Schema + DB Connection 
*
About the User Model 
•_id and username will be pulled from Twitter oauth 
•Most real data will be tracked in other models 
*
The Project Schema 
•In Go, project names are strings like “github. 
com/vkarpov15/mgo” 
•Releases a list of semver strings 
*
Why the data Field? 
•Simple and intuitive access control 
•data contains fields user can edit 
*
Project Schema Indexes 
•MongoDB has indexes for speeding up queries 
•Tradeoffs: may make writes slower 
•Project schema indexes on: 
* 
• Project name 
• Maintainers usernames (multi-key!) 
• Name and keywords text index (more in search section)
The Release Schema 
•Semver release of a project (with download info) 
*
Validators in Mongoose 
•validate ensures name exists and version is valid 
semver 
*
Virtuals in Mongoose 
•stringify can be accessed as a property 
*
Indexes for Release Schema 
•Indexes can be ordered to help with sorting 
•The -1 means higher releaseNumbers come first 
•Indexes define how you’ll query your data 
*
Last Schema: DownloadHistory 
•Because you want to highlight popular packages 
*
DownloadHistory Indexes 
•For the two common use cases of DownloadHistory 
* 
• How many downloads did a package have this month? 
• What are the most popular packages this month?
Schema Design Takeaways 
•Design schemas carefully 
•Use indexes that fit your use cases 
•Don’t go overboard on indexing everything! 
•Use Mongoose for seamless validation + casting 
*
Step 3: REST-ish API with Express 
•Express: powerful lightweight web framework 
•Highly customizable (> 6900 packages on npm) 
•Rapidly growing user base: 
* 
• NBC 
• SegmentIO 
• MySpace
Whats in an API? 
•API = actions on top of objects 
•REST principles: use HTTP error codes and verbs 
•Key concerns for API scalability: 
* 
• Load search results piece-by-piece from DB 
• Hit indexes 
• Don’t preclude horizontal scalability (multiple servers) 
•MEAN stack allows you to be very lazy
API Basics: Load a Project By Name 
•GET /api/project?project=gopkg.in/mgo 
*
A Slide Dedicated to a Bad Pun 
•Only place where Axl can tolerate a Slash :) 
•(Slash was the guitarist for GNR. He and Axl don’t like each other) 
*
Brief Aside on Dependency Injection 
•Using my lightweight DI helper, omni-di 
•Tool for managing and constructing dependencies 
•Create objects once, pass them in to functions 
•Injector inspects parameter names to find correct 
dependencies 
*
Brief Aside on Dependency Injection 
*
Routes With Dependency Injection 
*
Using the Express Router 
*
Filling out the Project API 
*
Brief Aside: Authentication 
•Twitter Oauth with redirect 
•Passport: Express-compatible login middleware 
*
Brief Aside: Authentication 
*
POST = Create a Project 
•POST /api/project - Mongoose is magical 
*
PUT = Modify an Existing Project 
*
More Sophisticated: Semver Query 
•Find me a Release that matches “~1.2” 
•GET /api/release?project=gopkg.in/mgo&version=~1.2 
•Perfect application of streams 
•Hard to index semver queries 
*
More Sophisticated: Semver Query 
*
Streaming Document by Document 
•Like a for loop, but don’t load whole array in RAM 
*
And If You Don’t Find a Document... 
•Return a nice, handy 404 
*
POST /api/release 
•The most important and most sophisticated 
•Subtleties: 
* 
• Race conditions between multiple servers 
• Error handling 
• CDN (or, why the “scale npm” campaign happened) 
• Authorization
Pushing a new Release 
•POST /api/release?project=gopkg.in/mgo&version=1.2.0 
*
MongoDB for Multi-server 
Concurrency 
•MongoDB operations are ACID per document 
•ACID stands for 
* 
• Atomic 
• Consistent 
• Isolated 
• Durable 
•FindAndModify underlies Mongoose 
findOneAndUpdate()
Multi-Server POST /api/release 
•findOneAndUpdate is ACID means a version gets 
added to a project only once 
•Multiple servers => only one wins 
*
The isNew Flag 
•isNew = false means “return document before update” 
*
POST /api/release Checks, Part 1 
*
POST /api/release Checks, Part 2 
•Check if release existed before findOneAndUpdate 
•If so, return handy conflict error 
*
Pushing To Amazon S3 
•Easy to set up Cloudfront on top of Amazon S3 
•Node lets you stream files to S3 
•No more worrying about server HD space 
*
Pushing To Amazon S3 
*
Using PipeToS3 
*
Step 3: Testing the API 
•Writing API is easy, testing can be hard 
•But easy with Express + Mocha + Node! 
•Stub out authentication 
•Event-driven nature of JS: no interrupts 
•Single process responsible for: 
* 
• Running Express server 
• Sending HTTP requests to Express server 
• Using Mocha to test the results of HTTP requests
Step 4: Testing the API 
•Writing API is easy, testing can be hard 
•But easy with Express + Mocha + Node! 
•Stub out authentication 
•Event-driven nature of JS: no interrupts 
•Single process responsible for: 
* 
• Running Express server 
• Sending HTTP requests to Express server 
• Using Mocha to test the results of HTTP requests
Why One Process? 
•Minimal setup 
•Run tests with one command 
•Use real configuration 
•Can assert on state of DB as well as result 
*
High Level Mocha Structure 
*
General Idea for Release API Tests 
*
First Case: Load Exact Version 
*
Test Loading Version with Semver 
*
Test Uploading a Release 
*
Testing Workflow 
•Systems like Gulp are sometimes overkill 
•Don’t ask people to “npm install mocha -g”! 
* 
• Version management 
• Incompatibilities with different projects versions 
• Breaks the npm install promise
Using Makefile for Testing 
•Makefile surprisingly common in NodeJS 
•Usually as a command shortener 
•Use “make api-test” to run tests 
*
Brief Demo of Tests 
*
Step 5: Search API 
•Use testing framework to do some TDD 
•Test-driven Development: tests first, then code 
•Usually done with unit tests 
•Faster and more fun with API integration tests 
*
TDD First Step 
*
Assumptions from Test 
•GET /api/search?q=test 
•Search project name and keywords 
•Return list of projects in JSON 
*
MongoDB Text Search 
•Introduced in MongoDB 2.6 (beta feature in 2.4) 
•Does exactly what this search API needs 
•First need to create a text index 
*
Filling Out The Search API 
*
Notes on Text Search 
•Requires mongoose >= 3.8.9 
•The $meta keyword used to get “text score” 
•Higher text score => more relevant 
•Usually want to sort by text result 
•Supports stemming in 15 languages 
*
What is Stemming? 
*
What is Stemming? 
•“Test” matches both “test” and “testing” 
*
Step 6: AngularJS SPA Client 
•REST API is only the beginning 
•What about building a client? 
•AngularJS is the best tool for the job (IMO) 
* 
• MVC-ish client-side templating framework 
• Two-way data binding 
• Dependency injection, elegant structure 
•Writing client-side JS is painful - use Browserify 
•Won’t need very sophisticated AngularJS for Axl
Book Announcement 
•My book on AngularJS is coming out Dec 22 
•Pre-order on Amazon for a more detailed dive into 
AngularJS 
*
Overview of AngularJS 
•Client-side templates (Two-way data binding) 
•Client-side routing (Single Page Apps) 
*
Why a Single Page App? 
•Clean separation of data and views 
•Ship HTML separately from data 
•Enables you to store HTML as static asset 
(Cloudfront) 
•Leaves your server free to serve up JSON 
•Cleaner separation of concerns 
*
Overview of Browserify 
•Compiles NodeJS JS into one browser-friendly file 
•Use same dependencies on client and server: 
* 
• moment 
• underscore 
• mongoose (schemas + validation only) 
• other isomorphic JS 
•Easy to upload JS to Cloudfront as static asset
Using AngularJS and Browserify 
•npm has an angular package 
•Only includes “core angular” 
•You may still need other packages 
*
Word of Warning 
•npm angular package depends on contextify 
•Contextify is notoriously picky about install reqs 
•You need right version of python and a C++ compiler 
•Possible, but tricky, to install on Windows 
•I prefer to list angular as a devDependency in 
package.json 
*
Writing AngularJS in NodeJS 
•Create an AngularJS “module” 
•Axl also needs the angular client-side routing 
module 
*
Setting up Client Side Routing 
*
How Client-Side Routing Works 
•Only modify hash portion of the URL 
*
What Does a Template Look Like? 
•Written in Jade: 
•“ng-” and “{{ }}” are tie-ins to AngularJS 
*
Ok, So What’s a Controller? 
•Defines an in-HTML API for the template to use 
•Responsible for loading and organizing data 
•Attaches properties to template “scope” 
*
And What’s $projects? 
•A service 
•Typically a convenience wrapper around a resource 
loaded from the server 
*
How Do Controllers and Services Get 
Added to AngularJS? 
*
Compiling with Browserify 
•Output ./bin/javascript/ui.js with all JavaScript 
*
Using Compiled JS 
•In base jade file, layout.jade, include ui.js: 
•Browserify downside: need to compile before use 
*
Compiling Templates 
•Jade downside: need to compile to HTML 
•Jade has significant upsides over static HTML: 
* 
• Readability 
• Can include conditionals on server configuration 
• Handy for testing - next section 
•So we also need to compile Jade!
Why Compile Templates 
•Jade downside: need to compile to HTML 
•Jade has significant upsides over static HTML: 
* 
• Readability 
• Can include conditionals on server configuration 
• Handy for testing - next section 
•So we also need to compile Jade!
Idea For Compiling Jade 
*
Compiling Templates Wrapup 
•AngularJS templates need to be HTML 
•Very easy to compile Jade 
•Take advantage of server configuration 
*
Step 7: Testing the AngularJS Client 
•Trickiest part of any project: users will run your code 
in different OS, browser, machine, etc. 
•My job at MongoDB = this for the mongodb server 
•Great tools for this in web-dev world: 
* 
• Sauce: think Amazon EC2 for browsers 
• Karma: Popular browser automation tool 
• ngScenario: AngularJS E2E testing framework
DOM Integration Tests 
•Test the whole browser side of your code 
•That is, test AngularJS’ integration with the DOM 
•Stub out REST API calls (speed and ease of setup) 
•Setting up data for E2E tests is often complex 
•Sometimes known as a “midway test” 
*
Karma Overview 
•Interface for launching a browser and running tests 
•Rich set of plugins 
•Handles tunneling for remote browsers 
•Plugins for launching 
* 
• local browsers (chrome, firefox, IE, etc.) 
• browsers in the Sauce cloud 
•My answer to “if I were stuck on a desert island with 
only one npm module”
Tradeoffs, Local vs Sauce 
•I recommend doing both 
•Sauce allows you to spawn any browser: 
* 
• Chrome on Linux 
• IE6 on WinXP 
• Android 4.3 (yes, mobile included) 
•But is slow and flakey 
•Local is difficult to set up, but: 
• Easier to debug: you can actually see the tests run 
• Fast and reliable
Workflow and Local vs Sauce 
•Make sure tests run with local config on Chrome 
•Then use Sauce to run tests on different browsers 
•Karma makes this easy: different configs 
*
Karma Plugin Ecosystem 
•Karma itself is a lightweight core 
•Need plugins to make it do anything useful 
•Yet another npm package with its own npm package 
ecosystem (~170 plugins) 
*
Generating a Karma Config 
•Karma configs are pretty straightforward 
•Karma has some handy tools: 
* 
• “node_modules/karma/bin/karma init” creates a new 
config after asking you a few questions 
•Or just copy/paste examples
Local Karma Config for Axl 
*
Sauce Karma Config - Browser List 
*
Sauce Karma Config - The Rest 
*
Karma Sauce Environment Vars 
•karma-sauce-launcher relies on 2 env variables: 
* 
• SAUCE_USERNAME: your Sauce username 
• SAUCE_ACCESS_KEY: Sauce API key 
•Make sure these are set or your tests will fail
Writing the Actual DOM Tests 
*
Couple Words of Warning 
•The api() function is home-baked 
•The AngularJS equivalent, $httpBackend, is weird 
•More about $httpBackend in Chapter 9 of 
Professional AngularJS :) 
•ngScenario is quirky and technically deprecated 
•Its replacement, Protractor, is more quirky and 
doesn’t support DOM integration tests 
*
How Does the API Function Work? 
•ngScenario DSL: domain specific language 
*
window.AxlAPI 
•Use a different layout.jade for running tests: 
* 
• Don’t load bootstrap 
• Expose methods to stub out API requests 
•ngScenario runs your tests in an iframe, so it can 
actually interact with the code under test
window.AxlAPI 
*
Makefile Rules for Running Tests 
•Remember, need env vars for Sauce tests 
*
Demo of Running DOM Tests 
*
Step 8: Deploying to S3 with Gulp 
•With SPA, your HTML is static 
•Might as well push it out to a CDN 
•Last step, stay focused! 
*
Overview of Gulp 
•Simple build tool for web apps 
•Another core package with a lot of plugins 
•Grunt is its more well-known competitor 
•Advantage of Gulp: its plain NodeJS 
•List tasks in gulpfile.js 
•Re-use your existing code and use streams! 
*
Including Gulp in package.json 
*
Minifying JS with Gulp 
*
Uploading to S3 with Gulp Overview 
*
Uploading Templates to S3 with Gulp 
*
Configuring AngularJS to Load 
Templates Remotely 
*
Configuring Jade to Load Templates 
Remotely 
*
And the End Result 
*
And that’s a wrap! Time to Review 
•Single page app with MEAN stack 
•Mongoose Schema 
•Express API 
•AngularJS routing 
•Browserify for building client code 
•Karma for testing 
•Gulp for pushing HTML+JS to S3+Cloudfront 
*
Thanks for Listening! 
•Slides on: 
* 
• Twitter: @code_barbarian 
• Slideshare: slideshare.net/vkarpov15 
•Repo on github: https://github.com/vkarpov15/axl-server 
•Professional AngularJS on Amazon

Más contenido relacionado

La actualidad más candente

From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN StackTroy Miles
 
MEAN Stack
MEAN StackMEAN Stack
MEAN StackDotitude
 
Mean Stack - An Overview
Mean Stack - An OverviewMean Stack - An Overview
Mean Stack - An OverviewNaveen Pete
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With JestBen McCormick
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN StackValeri Karpov
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentIrfan Maulana
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourValeri Karpov
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web applicationOliver N
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of dockerPHP Indonesia
 
The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1Haci Murat Yaman
 
MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013Valeri Karpov
 
MongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackdivyapisces
 
Introduction to the MEAN stack
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stackYoann Gotthilf
 
Introduction to mean stack
Introduction to mean stackIntroduction to mean stack
Introduction to mean stackPraveen Gubbala
 

La actualidad más candente (18)

From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Mean Stack - An Overview
Mean Stack - An OverviewMean Stack - An Overview
Mean Stack - An Overview
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN Stack
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 Hour
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web application
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of docker
 
The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1
 
Node js projects
Node js projectsNode js projects
Node js projects
 
MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013
 
MongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB and the MEAN Stack
MongoDB and the MEAN Stack
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
 
Introduction to the MEAN stack
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stack
 
Introduction to mean stack
Introduction to mean stackIntroduction to mean stack
Introduction to mean stack
 
MEAN Stack
MEAN Stack MEAN Stack
MEAN Stack
 

Similar a MEAN Stack WeNode Barcelona Workshop

Developing and Testing a MongoDB and Node.js REST API
Developing and Testing a MongoDB and Node.js REST APIDeveloping and Testing a MongoDB and Node.js REST API
Developing and Testing a MongoDB and Node.js REST APIAll Things Open
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularMark Leusink
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
Webinar: Get Started with the MEAN Stack
Webinar: Get Started with the MEAN StackWebinar: Get Started with the MEAN Stack
Webinar: Get Started with the MEAN StackMongoDB
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovMongoDB
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovMongoDB
 
Free Mongo on OpenShift
Free Mongo on OpenShiftFree Mongo on OpenShift
Free Mongo on OpenShiftSteven Pousty
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development PipelineGlobalLogic Ukraine
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-upTroy Miles
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Hannes Lowette
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB
 
OpenShift with Eclipse Tooling - EclipseCon 2012
OpenShift with Eclipse Tooling - EclipseCon 2012OpenShift with Eclipse Tooling - EclipseCon 2012
OpenShift with Eclipse Tooling - EclipseCon 2012Steven Pousty
 
DevOps and AWS - Code PaLOUsa 2017
DevOps and AWS  - Code PaLOUsa 2017DevOps and AWS  - Code PaLOUsa 2017
DevOps and AWS - Code PaLOUsa 2017James Strong
 
Front-End Tools and Workflows
Front-End Tools and WorkflowsFront-End Tools and Workflows
Front-End Tools and WorkflowsSara Vieira
 
ASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and ToolingASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and Tooling💻 Spencer Schneidenbach
 

Similar a MEAN Stack WeNode Barcelona Workshop (20)

Developing and Testing a MongoDB and Node.js REST API
Developing and Testing a MongoDB and Node.js REST APIDeveloping and Testing a MongoDB and Node.js REST API
Developing and Testing a MongoDB and Node.js REST API
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
Webinar: Get Started with the MEAN Stack
Webinar: Get Started with the MEAN StackWebinar: Get Started with the MEAN Stack
Webinar: Get Started with the MEAN Stack
 
Hello world - intro to node js
Hello world - intro to node jsHello world - intro to node js
Hello world - intro to node js
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
Free Mongo on OpenShift
Free Mongo on OpenShiftFree Mongo on OpenShift
Free Mongo on OpenShift
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
OpenShift with Eclipse Tooling - EclipseCon 2012
OpenShift with Eclipse Tooling - EclipseCon 2012OpenShift with Eclipse Tooling - EclipseCon 2012
OpenShift with Eclipse Tooling - EclipseCon 2012
 
DevOps and AWS - Code PaLOUsa 2017
DevOps and AWS  - Code PaLOUsa 2017DevOps and AWS  - Code PaLOUsa 2017
DevOps and AWS - Code PaLOUsa 2017
 
Front-End Tools and Workflows
Front-End Tools and WorkflowsFront-End Tools and Workflows
Front-End Tools and Workflows
 
ASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and ToolingASP.NET Core - Phillosophies, Processes and Tooling
ASP.NET Core - Phillosophies, Processes and Tooling
 
Top 10 web application development frameworks 2016
Top 10 web application development frameworks 2016Top 10 web application development frameworks 2016
Top 10 web application development frameworks 2016
 

Más de Valeri Karpov

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONValeri Karpov
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceValeri Karpov
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceValeri Karpov
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/AwaitValeri Karpov
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptValeri Karpov
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptValeri Karpov
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and ArchetypeValeri Karpov
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...Valeri Karpov
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Valeri Karpov
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerValeri Karpov
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonValeri Karpov
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June MeetupValeri Karpov
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondValeri Karpov
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataValeri Karpov
 
Mongo db in 3 minutes BoilerMake
Mongo db in 3 minutes   BoilerMakeMongo db in 3 minutes   BoilerMake
Mongo db in 3 minutes BoilerMakeValeri Karpov
 
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationAngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationValeri Karpov
 

Más de Valeri Karpov (16)

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSON
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-Service
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-Service
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScript
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScript
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and Archetype
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrinceton
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June Meetup
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game Data
 
Mongo db in 3 minutes BoilerMake
Mongo db in 3 minutes   BoilerMakeMongo db in 3 minutes   BoilerMake
Mongo db in 3 minutes BoilerMake
 
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationAngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

MEAN Stack WeNode Barcelona Workshop

  • 1. Guided MEAN Stack Hackathon Building (and Testing) a Single Page App in 2 Hours Valeri Karpov Software Engineer, MongoDB www.thecodebarbarian.com www.slideshare.net/vkarpov15 github.com/vkarpov15 @code_barbarian
  • 2. Who is this guy? •Coined the MEAN stack in April ‘13 •CI/Tools/NodeJS/Go Engineer at MongoDB •Maintains mongoose, omni-di •AngularJS since 0.9.4 in 2010 •Hackmaster General at Bookalokal •Former CTO, LevelUp *
  • 3. General Outline •MEAN = MongoDB, ExpressJS, AngularJS, NodeJS •Beginner talk: high-level concepts of MEAN •Emphasis on testing and workflow •Building a single page app - Axl •NPM-inspired Package Manager for Golang •Browser interface only •No Go knowledge required *
  • 5. What You’re Building •Server for semver-aware package manager *
  • 6. Concepts You’ll Be Learning About •Streams •API testing •DOM integration tests with Sauce •Build systems and architecture •Configuration + workflow •General principles for writing NPM packages *
  • 7. NPM Packages You’ll Be Using •mocha: unit tests and API integration tests •browserify: compile Node JS into browser JS •mongoose: schema validation for Node + MongoDB •karma: browser automation for testing •gulp: general-purpose build workflow •And several more *
  • 8. Step By Step, the Server Side •Step 1: Define the problem + brief overview of Go •Step 2: Define schema and models (mongoose) •Step 3: Build an API (express) •Step 4: API-level testing (mocha) •Step 5: Extending the API to support search *
  • 9. Step By Step, the HTML Client Side •Step 6: Create AngularJS SPA client (browserify) •Step 7: Testing the Single Page App (karma) •Step 8: CDN for templates and JS (gulp) *
  • 10. Step 1: A Brief Overview of Go •Language developed by Google •Cute toy language with some niche use cases: * • Fast-compiling small native binaries • Tight integration with C • “Agent” programs like MongoDB MMS agents •Has some bad limitations • Generics • Package management
  • 12. Why Build a Go Package Manager •npm gets package management mostly right •Go doesn’t and could use some help *
  • 13. What npm Does Right •Mostly semantic versioning (no v20130722) * • Will my code break if I upgrade from v2.1.3 to v2.1.4? •2 commands to install and test • npm install • npm test • And you’re ready to hack •No need to change PATH or env variables •Result: a package for every use case •Go doesn’t have any of this
  • 14. Goals for Axl Server •Upload/download releases of projects •Projects hosted on Amazon Cloudfront (streams!) •Query for projects using semver syntax: * • version 1.2.0 matches “~1.2”, “>=1.2.0”, “<=1.3.0”, etc. • Thankfully, there’s an npm module for that •Ability to search projects by keyword •Sane build system and workflow •Take advantage of a single page app
  • 15. Step 2: Design Schemas “Smart data structures and dumb code works a lot better than the other way around.” * - Eric S. Raymond “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” - Linus Torvalds
  • 16. A Brief Overview of Mongoose •MongoDB is schema-less •But your schema design still matters! •Mongoose = NodeJS schemas for MongoDB * • Validation • Casting for objects and queries • Promises and other syntactic sugar • Object document mapper (ODM) •Users include Tinder and McDonalds
  • 17. Simple Example: A User Schema *
  • 18. Model = Schema + DB Connection *
  • 19. About the User Model •_id and username will be pulled from Twitter oauth •Most real data will be tracked in other models *
  • 20. The Project Schema •In Go, project names are strings like “github. com/vkarpov15/mgo” •Releases a list of semver strings *
  • 21. Why the data Field? •Simple and intuitive access control •data contains fields user can edit *
  • 22. Project Schema Indexes •MongoDB has indexes for speeding up queries •Tradeoffs: may make writes slower •Project schema indexes on: * • Project name • Maintainers usernames (multi-key!) • Name and keywords text index (more in search section)
  • 23. The Release Schema •Semver release of a project (with download info) *
  • 24. Validators in Mongoose •validate ensures name exists and version is valid semver *
  • 25. Virtuals in Mongoose •stringify can be accessed as a property *
  • 26. Indexes for Release Schema •Indexes can be ordered to help with sorting •The -1 means higher releaseNumbers come first •Indexes define how you’ll query your data *
  • 27. Last Schema: DownloadHistory •Because you want to highlight popular packages *
  • 28. DownloadHistory Indexes •For the two common use cases of DownloadHistory * • How many downloads did a package have this month? • What are the most popular packages this month?
  • 29. Schema Design Takeaways •Design schemas carefully •Use indexes that fit your use cases •Don’t go overboard on indexing everything! •Use Mongoose for seamless validation + casting *
  • 30. Step 3: REST-ish API with Express •Express: powerful lightweight web framework •Highly customizable (> 6900 packages on npm) •Rapidly growing user base: * • NBC • SegmentIO • MySpace
  • 31. Whats in an API? •API = actions on top of objects •REST principles: use HTTP error codes and verbs •Key concerns for API scalability: * • Load search results piece-by-piece from DB • Hit indexes • Don’t preclude horizontal scalability (multiple servers) •MEAN stack allows you to be very lazy
  • 32. API Basics: Load a Project By Name •GET /api/project?project=gopkg.in/mgo *
  • 33. A Slide Dedicated to a Bad Pun •Only place where Axl can tolerate a Slash :) •(Slash was the guitarist for GNR. He and Axl don’t like each other) *
  • 34. Brief Aside on Dependency Injection •Using my lightweight DI helper, omni-di •Tool for managing and constructing dependencies •Create objects once, pass them in to functions •Injector inspects parameter names to find correct dependencies *
  • 35. Brief Aside on Dependency Injection *
  • 36. Routes With Dependency Injection *
  • 37. Using the Express Router *
  • 38. Filling out the Project API *
  • 39. Brief Aside: Authentication •Twitter Oauth with redirect •Passport: Express-compatible login middleware *
  • 41. POST = Create a Project •POST /api/project - Mongoose is magical *
  • 42. PUT = Modify an Existing Project *
  • 43. More Sophisticated: Semver Query •Find me a Release that matches “~1.2” •GET /api/release?project=gopkg.in/mgo&version=~1.2 •Perfect application of streams •Hard to index semver queries *
  • 45. Streaming Document by Document •Like a for loop, but don’t load whole array in RAM *
  • 46. And If You Don’t Find a Document... •Return a nice, handy 404 *
  • 47. POST /api/release •The most important and most sophisticated •Subtleties: * • Race conditions between multiple servers • Error handling • CDN (or, why the “scale npm” campaign happened) • Authorization
  • 48. Pushing a new Release •POST /api/release?project=gopkg.in/mgo&version=1.2.0 *
  • 49. MongoDB for Multi-server Concurrency •MongoDB operations are ACID per document •ACID stands for * • Atomic • Consistent • Isolated • Durable •FindAndModify underlies Mongoose findOneAndUpdate()
  • 50. Multi-Server POST /api/release •findOneAndUpdate is ACID means a version gets added to a project only once •Multiple servers => only one wins *
  • 51. The isNew Flag •isNew = false means “return document before update” *
  • 53. POST /api/release Checks, Part 2 •Check if release existed before findOneAndUpdate •If so, return handy conflict error *
  • 54. Pushing To Amazon S3 •Easy to set up Cloudfront on top of Amazon S3 •Node lets you stream files to S3 •No more worrying about server HD space *
  • 57. Step 3: Testing the API •Writing API is easy, testing can be hard •But easy with Express + Mocha + Node! •Stub out authentication •Event-driven nature of JS: no interrupts •Single process responsible for: * • Running Express server • Sending HTTP requests to Express server • Using Mocha to test the results of HTTP requests
  • 58. Step 4: Testing the API •Writing API is easy, testing can be hard •But easy with Express + Mocha + Node! •Stub out authentication •Event-driven nature of JS: no interrupts •Single process responsible for: * • Running Express server • Sending HTTP requests to Express server • Using Mocha to test the results of HTTP requests
  • 59. Why One Process? •Minimal setup •Run tests with one command •Use real configuration •Can assert on state of DB as well as result *
  • 60. High Level Mocha Structure *
  • 61. General Idea for Release API Tests *
  • 62. First Case: Load Exact Version *
  • 63. Test Loading Version with Semver *
  • 64. Test Uploading a Release *
  • 65. Testing Workflow •Systems like Gulp are sometimes overkill •Don’t ask people to “npm install mocha -g”! * • Version management • Incompatibilities with different projects versions • Breaks the npm install promise
  • 66. Using Makefile for Testing •Makefile surprisingly common in NodeJS •Usually as a command shortener •Use “make api-test” to run tests *
  • 67. Brief Demo of Tests *
  • 68. Step 5: Search API •Use testing framework to do some TDD •Test-driven Development: tests first, then code •Usually done with unit tests •Faster and more fun with API integration tests *
  • 70. Assumptions from Test •GET /api/search?q=test •Search project name and keywords •Return list of projects in JSON *
  • 71. MongoDB Text Search •Introduced in MongoDB 2.6 (beta feature in 2.4) •Does exactly what this search API needs •First need to create a text index *
  • 72. Filling Out The Search API *
  • 73. Notes on Text Search •Requires mongoose >= 3.8.9 •The $meta keyword used to get “text score” •Higher text score => more relevant •Usually want to sort by text result •Supports stemming in 15 languages *
  • 75. What is Stemming? •“Test” matches both “test” and “testing” *
  • 76. Step 6: AngularJS SPA Client •REST API is only the beginning •What about building a client? •AngularJS is the best tool for the job (IMO) * • MVC-ish client-side templating framework • Two-way data binding • Dependency injection, elegant structure •Writing client-side JS is painful - use Browserify •Won’t need very sophisticated AngularJS for Axl
  • 77. Book Announcement •My book on AngularJS is coming out Dec 22 •Pre-order on Amazon for a more detailed dive into AngularJS *
  • 78. Overview of AngularJS •Client-side templates (Two-way data binding) •Client-side routing (Single Page Apps) *
  • 79. Why a Single Page App? •Clean separation of data and views •Ship HTML separately from data •Enables you to store HTML as static asset (Cloudfront) •Leaves your server free to serve up JSON •Cleaner separation of concerns *
  • 80. Overview of Browserify •Compiles NodeJS JS into one browser-friendly file •Use same dependencies on client and server: * • moment • underscore • mongoose (schemas + validation only) • other isomorphic JS •Easy to upload JS to Cloudfront as static asset
  • 81. Using AngularJS and Browserify •npm has an angular package •Only includes “core angular” •You may still need other packages *
  • 82. Word of Warning •npm angular package depends on contextify •Contextify is notoriously picky about install reqs •You need right version of python and a C++ compiler •Possible, but tricky, to install on Windows •I prefer to list angular as a devDependency in package.json *
  • 83. Writing AngularJS in NodeJS •Create an AngularJS “module” •Axl also needs the angular client-side routing module *
  • 84. Setting up Client Side Routing *
  • 85. How Client-Side Routing Works •Only modify hash portion of the URL *
  • 86. What Does a Template Look Like? •Written in Jade: •“ng-” and “{{ }}” are tie-ins to AngularJS *
  • 87. Ok, So What’s a Controller? •Defines an in-HTML API for the template to use •Responsible for loading and organizing data •Attaches properties to template “scope” *
  • 88. And What’s $projects? •A service •Typically a convenience wrapper around a resource loaded from the server *
  • 89. How Do Controllers and Services Get Added to AngularJS? *
  • 90. Compiling with Browserify •Output ./bin/javascript/ui.js with all JavaScript *
  • 91. Using Compiled JS •In base jade file, layout.jade, include ui.js: •Browserify downside: need to compile before use *
  • 92. Compiling Templates •Jade downside: need to compile to HTML •Jade has significant upsides over static HTML: * • Readability • Can include conditionals on server configuration • Handy for testing - next section •So we also need to compile Jade!
  • 93. Why Compile Templates •Jade downside: need to compile to HTML •Jade has significant upsides over static HTML: * • Readability • Can include conditionals on server configuration • Handy for testing - next section •So we also need to compile Jade!
  • 95. Compiling Templates Wrapup •AngularJS templates need to be HTML •Very easy to compile Jade •Take advantage of server configuration *
  • 96. Step 7: Testing the AngularJS Client •Trickiest part of any project: users will run your code in different OS, browser, machine, etc. •My job at MongoDB = this for the mongodb server •Great tools for this in web-dev world: * • Sauce: think Amazon EC2 for browsers • Karma: Popular browser automation tool • ngScenario: AngularJS E2E testing framework
  • 97. DOM Integration Tests •Test the whole browser side of your code •That is, test AngularJS’ integration with the DOM •Stub out REST API calls (speed and ease of setup) •Setting up data for E2E tests is often complex •Sometimes known as a “midway test” *
  • 98. Karma Overview •Interface for launching a browser and running tests •Rich set of plugins •Handles tunneling for remote browsers •Plugins for launching * • local browsers (chrome, firefox, IE, etc.) • browsers in the Sauce cloud •My answer to “if I were stuck on a desert island with only one npm module”
  • 99. Tradeoffs, Local vs Sauce •I recommend doing both •Sauce allows you to spawn any browser: * • Chrome on Linux • IE6 on WinXP • Android 4.3 (yes, mobile included) •But is slow and flakey •Local is difficult to set up, but: • Easier to debug: you can actually see the tests run • Fast and reliable
  • 100. Workflow and Local vs Sauce •Make sure tests run with local config on Chrome •Then use Sauce to run tests on different browsers •Karma makes this easy: different configs *
  • 101. Karma Plugin Ecosystem •Karma itself is a lightweight core •Need plugins to make it do anything useful •Yet another npm package with its own npm package ecosystem (~170 plugins) *
  • 102. Generating a Karma Config •Karma configs are pretty straightforward •Karma has some handy tools: * • “node_modules/karma/bin/karma init” creates a new config after asking you a few questions •Or just copy/paste examples
  • 103. Local Karma Config for Axl *
  • 104. Sauce Karma Config - Browser List *
  • 105. Sauce Karma Config - The Rest *
  • 106. Karma Sauce Environment Vars •karma-sauce-launcher relies on 2 env variables: * • SAUCE_USERNAME: your Sauce username • SAUCE_ACCESS_KEY: Sauce API key •Make sure these are set or your tests will fail
  • 107. Writing the Actual DOM Tests *
  • 108. Couple Words of Warning •The api() function is home-baked •The AngularJS equivalent, $httpBackend, is weird •More about $httpBackend in Chapter 9 of Professional AngularJS :) •ngScenario is quirky and technically deprecated •Its replacement, Protractor, is more quirky and doesn’t support DOM integration tests *
  • 109. How Does the API Function Work? •ngScenario DSL: domain specific language *
  • 110. window.AxlAPI •Use a different layout.jade for running tests: * • Don’t load bootstrap • Expose methods to stub out API requests •ngScenario runs your tests in an iframe, so it can actually interact with the code under test
  • 112. Makefile Rules for Running Tests •Remember, need env vars for Sauce tests *
  • 113. Demo of Running DOM Tests *
  • 114. Step 8: Deploying to S3 with Gulp •With SPA, your HTML is static •Might as well push it out to a CDN •Last step, stay focused! *
  • 115. Overview of Gulp •Simple build tool for web apps •Another core package with a lot of plugins •Grunt is its more well-known competitor •Advantage of Gulp: its plain NodeJS •List tasks in gulpfile.js •Re-use your existing code and use streams! *
  • 116. Including Gulp in package.json *
  • 117. Minifying JS with Gulp *
  • 118. Uploading to S3 with Gulp Overview *
  • 119. Uploading Templates to S3 with Gulp *
  • 120. Configuring AngularJS to Load Templates Remotely *
  • 121. Configuring Jade to Load Templates Remotely *
  • 122. And the End Result *
  • 123. And that’s a wrap! Time to Review •Single page app with MEAN stack •Mongoose Schema •Express API •AngularJS routing •Browserify for building client code •Karma for testing •Gulp for pushing HTML+JS to S3+Cloudfront *
  • 124. Thanks for Listening! •Slides on: * • Twitter: @code_barbarian • Slideshare: slideshare.net/vkarpov15 •Repo on github: https://github.com/vkarpov15/axl-server •Professional AngularJS on Amazon