Download - Node.js Dublin Meetup April 2014
© Copyright FeedHenry Ltd. 2013
Enterprise Node.js Development
Damian BeresfordTwitter: @dberesford
@feedhenry
1
Node.js Dublin April 2014
© Copyright FeedHenry Ltd. 2013
FeedHenry Platform
© Copyright FeedHenry Ltd. 2013
Customers
• Customers• Transport• Law Enforcement• Utilities• Aviation• Medical
• ‘Hello world’ Enterprise Proxy Pattern:
3
© Copyright FeedHenry Ltd. 2013
FeedHenry Open Source
4
© Copyright FeedHenry Ltd. 2013
Javascript
5
© Copyright FeedHenry Ltd. 2013
Node.js Anti Patterns
• Java mind set
• OOP
• Monolithic Systems
6
© Copyright FeedHenry Ltd. 2013
Anti Anti Patterns• Data! Functions! Modules!
• Callbacks, async, etc
• Functional Programming
• Underscore• Start with _each, _map, _filter, _reduce
• Unix/KISS mindset
• Microservices
7
© Copyright FeedHenry Ltd. 2013
Futurology
• Promises
• Generators• github.com/visionmedia/co
• Reactive Programming• Reactive Manifesto• RxJS• Bacon.js
8
© Copyright FeedHenry Ltd. 2013
Testing Stack
• Turbo – test runner
• Istanbul – code coverage
• Proxyquire – mock your require’s
• Grunt – ties it all together
• See FeedHenry Node.js Cloud Testing Guide
9
© Copyright FeedHenry Ltd. 2013
Testing Stack - Turbo
• Turbo • Test runner burn out – tight coupling of test running and code coverage• No fluff, no nuff, just executes exported functions in your test files• Per-file and global setUp and tearDown• Parallel by default – encourages stateless tests
10
© Copyright FeedHenry Ltd. 2013
Testing - Istanbul
• Code coverage with Istanbul
11
• Jenkins/CI integration
• Express Middleware – dynamic code coverage
© Copyright FeedHenry Ltd. 2013
Testing - Proxyquire
• Proxyquire: “Proxies nodejs require in order to allow overriding of dependencies during testing”
12
var request = require('request');
exports.search = function(params, cb) {
request('https://www.google.ie/?q=foo#q=foo', function(err, res, body) {
if (err) return cb(err);
return cb(null, body);
});
};exports.it_should_test_search = function(finish) {
var mockRequest = function(url, cb) {
console.log("in mock call to request!");
return cb(null, {}, 'Sample data!!');
};
var main = proxyquire('lib/foo.js', {request: mockRequest});
main.search(null, function(err, data) {
assert.ok(!err, 'Unexpected error: ' + util.inspect(err));
console.log("got data from search: ", data);
finish();
});
};
© Copyright FeedHenry Ltd. 2013
Testing – unit vs acceptance
• Eyes on code!
• unit tests should require no external dependencies, external services should be mocked out (e.g. internet access, writing to file/database, etc)
• unit tests should be super quick to run
• unit tests should be reliable as no external dependencies
• unit tests should just test your own logic
• acceptance tests can require external dependencies, which do require setup (which should be well documented!)
• as such they can take longer to run
• acceptance tests are a more 'end to end' philosophy
13
© Copyright FeedHenry Ltd. 2013
Micro Services
• martinfowler.com/articles/microservices.html
• yobriefca.se/blog/2013/04/29/micro-service-architecture
• slideshare.net/michaelneale/microservices-and-functional-programming
• klangism.tumblr.com/post/80087171446/microservices
• richardrodger.com/monolithic-nodejs
14
© Copyright FeedHenry Ltd. 2013
Mirco Services
• Mix of Message Bus and API
• API - JSON in JSON out (robustness principal)
• Message Bus – Rabbit MQ
• Not just node.js, DropWizard for Java
• Continuous Integration - Small Production Deploys
• Operations – monitor all the things
• Dedicated Ops and Support teams
15
© Copyright FeedHenry Ltd. 2013
Mirco Services – complexity
• Not a silver bullet – but does help with complexity• Still deal with lots of business rules, moving parts, etc• Easy !== Simple• Work at simplicity
• Need Master Builders to keep all the balls in the air
• Boxology
16
© Copyright FeedHenry Ltd. 2013
Misc
• Private NPM Registry: npm delegate (may move to Kappa)
• Docker – container awesomeness
• API Blueprint – readme on steroids
17
© Copyright FeedHenry Ltd. 2013
API Blueprint
18
© Copyright FeedHenry Ltd. 2013
API Blueprint
19
© Copyright FeedHenry Ltd. 2013
Thank you..
• Tanx!
• www.feedhenry.com/ for more…
20