Upload
ben-hall
View
129
Download
4
Tags:
Embed Size (px)
DESCRIPTION
Talk delivered at London Node User Group on 22nd October 2014. Talk covers my personal pain points, issues I've encountered with Node and some suggested alternatives
Citation preview
REAL WORLD LESSONS ON THE ANTI-PATTERNS OF NODE.JS
@Ben_Hall
Ben@BenHall .me.uk
Blog.BenHall .me.uk
MY BATTLE SCARS OF NODE.JS
@Ben_Hall
Ben@BenHall .me.uk
Blog.BenHall .me.uk
MY LIFE, MY STORY, MY ANTI-PATTERNS
BY BEN HALL.
PUBLISHER TBC
$ whoami
Ocelot Uproar
Tea boy > Tester > Developer > Freelancer > Tea boy?
My main pain points & agenda
• Modules + NPM
• Project Structure
• Async
• Error Handling
Disclaimer
Examples are not a refl ection on the developer/team/company. Based on
problems I ’ve caused myself or struggled with. JavaScript is very
subjective…blah blah blah… If you’re doing it r ight then *amazing*! I ’m
not.
Love, Ben x
MODULES + NPM
AngularJs 1.2 => 1.3
1. "dependenc ies" : {
2. "angu lar" : "^1.2 .16”
3. }
��
Angular 1.2 => 1.3
> angular.element(document)
[#document]
> angular.element(document)
TypeError: undefi ned is not a function
Lock Down Dependencies
Randomly breaking bui lds and deployments wil l occur
otherwise
$ npm shrinkwrap
Lock down dependencies to what’s running local ly
��
Hard code versions in package.json
1. "dependencies": {
2. "angular": “1.2.23”
3. }
��
$ npm outdated
$ npm install
Downloading the internet on each deployment can be
slow
��
$ npm install --production
��
“HELPERS” & PROJECT STRUCTURE
��
��
��
��
Libs/<Context>/<Task>.js
Why not an NPM?
��
��
ASYNC
Because J avaSc r ip t
Promises
Promises… Promises… Never break your promises.
Personal ly , never make promises.
http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/
��
Not part of the Node
Makes integration more diffi cult. Makes swapping
code in / out more painful.
Callbacks
So good it ’s got it ’s own website cal lbackhel l .com
��
��
Loops + Async Callbacks��
Loops + Async Callbacks��
Generators are coming!
See Node >=0.11.2
��
http://blog.alexmaccaw.com/how-yield-will-transform-node
��
ERROR HANDLING
Wasn’t great from the start
Sti l l not great
Try {} Catch {}��
Try {} Catch {}��
��
Returning String as Error��
��
Zones are coming!
See Node >=0.11.2
��
��
https://raw.githubusercontent.com/strongloop/zone/master/showcase/curl/curl-zone.js
Generators + Error Handling
��
��
AND FINALLY
Node is *Amazing*
Let’s you get away with a lot without hurting too much
Modules + NPM
Pro jec t S t ructure
Async
Error Hand l ing
@Ben_Hall
Ben@BenHall .me.uk
Blog.BenHall .me.uk