Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
REAL WORLD LESSONS ON 
THE ANTI -PATTERNS OF 
NODE.JS 
@Ben_Hal l 
Ben@BenHal l .me.uk 
Blog.BenHal l .me.uk
MY BATTLE SCARS OF 
NODE.JS 
@Ben_Hal l 
Ben@BenHal l .me.uk 
Blog.BenHal l .me.uk
MY LIFE, MY STORY, 
MY ANTI -PATTERNS 
BY BEN HALL. 
PUBLISHER TBC
$ whoami 
Tea boy > Tester > Developer > Freelancer > Tea boy? 
Ocelot Uproar
My main pain points & agenda 
• Modules + NPM 
• Project St ructure 
• Async 
• Er ror Handl ing
Disclaimer 
Examples are not a ref lect ion on the 
developer / team/company. Based on 
problems I ’ v e c a u s e d mysel...
MODULES + NPM
AngularJs 1.2 => 1.3 
1. "dependencies" : { 
2. " a n g u l a r " : " ^ 1 . 2 . 1 6 ” 
3. } 

Angular 1.2 => 1.3 
> angular.element (document ) 
[#document ] 
> angular.element (document ) 
TypeEr ror : undef ined is...
Lock Down Dependencies 
Randomly breaking bui lds and 
deployments wi l l occur 
otherwise
$ npm shrinkwrap 
Lock down dependencies to 
w h a t ’ s r u n n i n g l o c a l l y 

Hard code versions in 
package. json 
1. "dependencies" : { 
2. " a n g u l a r " : “ 1 . 2 . 2 3 ” 
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? 


Be c a u s e J a v aSc r i p t 
ASYNC
Promises 
P r o m i s e s… P r o m i s e s… N e v e r 
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 integrat ion more 
di f f icul t . Makes swapping code 
in / out more painful .
Callbacks 
S o g o o d i t ’ s g o t i t ’ s o w n 
websi te 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 
St i 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*
L e t ’s y o u g e t awa y wi t h a l o t 
wi thout hurt ing too much 
Modules + NPM 
Projec t St ruc ture 
As ync 
Er ror...
@Ben_Hal l 
Ben@BenHal l .me.uk 
Blog.BenHal l .me.uk
Real World Lessons On The Anti-Patterns of Node.JS
Real World Lessons On The Anti-Patterns of Node.JS
Real World Lessons On The Anti-Patterns of Node.JS
Real World Lessons On The Anti-Patterns of Node.JS
Próxima SlideShare
Cargando en…5
×

Real World Lessons On The Anti-Patterns of Node.JS

460 visualizaciones

Publicado el

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

Publicado en: Tecnología
  • Sé el primero en comentar

Real World Lessons On The Anti-Patterns of Node.JS

  1. 1. REAL WORLD LESSONS ON THE ANTI -PATTERNS OF NODE.JS @Ben_Hal l Ben@BenHal l .me.uk Blog.BenHal l .me.uk
  2. 2. MY BATTLE SCARS OF NODE.JS @Ben_Hal l Ben@BenHal l .me.uk Blog.BenHal l .me.uk
  3. 3. MY LIFE, MY STORY, MY ANTI -PATTERNS BY BEN HALL. PUBLISHER TBC
  4. 4. $ whoami Tea boy > Tester > Developer > Freelancer > Tea boy? Ocelot Uproar
  5. 5. My main pain points & agenda • Modules + NPM • Project St ructure • Async • Er ror Handl ing
  6. 6. Disclaimer Examples are not a ref lect ion on the developer / team/company. Based on problems I ’ v e c a u s e d mysel f or st ruggled wi th. JavaScr ipt is very subject ive…b l a h b l a h b l a h… I f y o u ’ r e d o i n g i t r i g h t t h e n *amazing* ! I ’ m n o t . Love, Ben x
  7. 7. MODULES + NPM
  8. 8. AngularJs 1.2 => 1.3 1. "dependencies" : { 2. " a n g u l a r " : " ^ 1 . 2 . 1 6 ” 3. } 
  9. 9. Angular 1.2 => 1.3 > angular.element (document ) [#document ] > angular.element (document ) TypeEr ror : undef ined is not a funct ion
  10. 10. Lock Down Dependencies Randomly breaking bui lds and deployments wi l l occur otherwise
  11. 11. $ npm shrinkwrap Lock down dependencies to w h a t ’ s r u n n i n g l o c a l l y 
  12. 12. Hard code versions in package. json 1. "dependencies" : { 2. " a n g u l a r " : “ 1 . 2 . 2 3 ” 3. } 
  13. 13. $ npm outdated
  14. 14. $ npm install Downloading the internet on each deployment can be slow 
  15. 15. $ npm install --production 
  16. 16. “HELPERS” & PROJECT STRUCTURE 
  17. 17.
  18. 18.
  19. 19.
  20. 20. Libs/<Context>/<Task>.js Why not an NPM? 
  21. 21.
  22. 22. Be c a u s e J a v aSc r i p t ASYNC
  23. 23. Promises P r o m i s e s… P r o m i s e s… N e v e r break your promises. Personal ly, never make promises.
  24. 24.  http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/
  25. 25. Not part of the Node Makes integrat ion more di f f icul t . Makes swapping code in / out more painful .
  26. 26. Callbacks S o g o o d i t ’ s g o t i t ’ s o w n websi te cal lbackhel l .com
  27. 27.
  28. 28.
  29. 29. Loops + Async Callbacks 
  30. 30. Loops + Async Callbacks 
  31. 31. Generators are coming! See Node >=0.11.2 
  32. 32. http://blog.alexmaccaw.com/how-yield-will-transform-node 
  33. 33. ERROR HANDLING
  34. 34. Wasn’t great from the start St i l l not great
  35. 35. Try {} Catch {} 
  36. 36. Try {} Catch {} 
  37. 37.
  38. 38. Returning String as Error 
  39. 39.
  40. 40. Zones are coming! See Node >=0.11.2 
  41. 41.  https://raw.githubusercontent.com/strongloop/zone/master/showcase/curl/curl-zone.js
  42. 42. Generators + Error Handling
  43. 43.
  44. 44. AND FINALLY
  45. 45. Node is *Amazing*
  46. 46. L e t ’s y o u g e t awa y wi t h a l o t wi thout hurt ing too much Modules + NPM Projec t St ruc ture As ync Er ror Handl ing
  47. 47. @Ben_Hal l Ben@BenHal l .me.uk Blog.BenHal l .me.uk

×