How we're building Wercker

2,498
-1

Published on

Presentation for the first Amsterdam node.js meetup.

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

No Downloads
Views
Total Views
2,498
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

How we're building Wercker

  1. 1. Sunday, April 1, 12 020 node.js meetup
  2. 2. HOW WE’RE BUILDING WERCKER node.js essential modules and tools Micha Hernández van Leuffen Wouter Mooij @mies @wwwouter mies@wercker.com wouter@wercker.comSunday, April 1, 12
  3. 3. Continuous Deployment made easy wercker acceleratorSunday, April 1, 12
  4. 4. wercker Wercker is a hosted continuous deployment platform, helping developer-teams working on web-applications, push smaller pieces of code, such that bugs are quickly detected and resolved. It is easy to use and with you from the start.Sunday, April 1, 12
  5. 5. WHAT WE’RE USINGSunday, April 1, 12
  6. 6. TECHNOLOGY STACK BACKBONE.JS wercker WEBSOCKETS .net node.jsSunday, April 1, 12
  7. 7. EXPRESS ‣ Powers the Wercker API ‣ Similar to Sinatra in Ruby or Flask in Python ‣ Just Use It ‣ expressjs.comSunday, April 1, 12
  8. 8. EXPRESS // load dependencies var express = require(‘express’); var app = express.createServer(); // define routes, send JSON app.get(‘/posts’, function(req, res) { res.send({title: ‘this is a post’}); }); // use templating app.get(‘/posts/:id’, function(req, res) { res.render(‘post’, {title: ‘this is a post’}); });Sunday, April 1, 12
  9. 9. EXPRESS Pro T ip! // separate controller from routes in app.js var api = require(‘./controllers/api.js’); app.get(‘/posts’, api.getPosts); // have functionality reside in controllers/api.js exports getPosts = function(req, res) { res.send({title: ‘this is a post’}); });Sunday, April 1, 12
  10. 10. ASYNC Esca Callb ping ack Hell™ // separate controller from routes in app.js fs.stat(/awesome/file, function (err, stats) { parseData(stats, function(err, data) { db.insert(data, function(err, result) { // do something with error or result }); });Sunday, April 1, 12
  11. 11. ASYNC ‣ Control flow library (waterfall, series, parallel) ‣ Functional Programming methods (filter, map, reduce, forEach) ‣ Alternatives include (Step, Flow-js, node-promise) ‣ https://github.com/caolan/asyncSunday, April 1, 12
  12. 12. ASYNC async.waterfall([ function(callback){ fs.stat(/awesome/file, callback) }, function(stats, callback){ parseData(stats, callback); }, function(data, callback){ db.insert(json, callback); } ], // optional final callback to run once all functions have completed function (err, result) { // if there is an error it ends up here // otherwise this is the result of the db insert console.log(result); });Sunday, April 1, 12
  13. 13. REQUEST ‣ Sane HTTP requests ‣ Streaming Support ‣ Oauth signing ‣ Convenience methods ‣ https://github.com/mikeal/requestSunday, April 1, 12
  14. 14. REQUEST // simple HTTP ‘GET’ request var request = require(‘request’); request.get(http://api.twitter.com/1/statuses/public_timeline.json, function(error, response, body) { console.log(body); });Sunday, April 1, 12
  15. 15. MONGOOSE ‣ MongoDB = Document Oriented Database ‣ Mongoose = MongoDB ODM ‣ Easy to define and query models ‣ http://mongoosejs.com/Sunday, April 1, 12
  16. 16. MONGOOSE // define a model var mongoose = require(mongoose), Schema = mongoose.Schema, ObjectId = Schema.ObjectId; var projectSchema = new Schema({ name: String, git_url: String, user_id: {type: ObjectId, required: true, index: true}, private: {type: Boolean, default: true}, createdOn: {type: Date, default: Date.now}, }); module.exports = mongoose.model(Project, projectSchema);Sunday, April 1, 12
  17. 17. MONGOOSE // use a model var Project = require(‘project.js’); // Find objects Project.find({ user_id: id}, [‘name’,‘createdOn’], {sort: {createdOn: -1}}, function(err, projects) { // do something with array of projects }); // Retrieve a single object Project.findOne({ name: ‘mies’}, function(err, project) { // do something with the project }); // Create new Project p = new Project({name: ‘mies’...}).save();Sunday, April 1, 12
  18. 18. OTHERS ‣ nodeenv - sandbox node environments (https://github.com/ekalinin/nodeenv) ‣ socket.io - cross-browser websockets (http://socket.io) ‣ aws2js - Amazon Web Services module (https://github.com/SaltwaterC/aws2js) ‣ underscore.js - Functional Programming utilities (http://documentcloud.github.com/underscore/) ‣ Custom NPM install urls: "dependencies": { "everyauth": "git://github.com/mies/everyauth.git" }Sunday, April 1, 12
  19. 19. QUESTIONS?Sunday, April 1, 12

×