9 anti-patterns for node.js teams
-
Upload
jeff-harrell -
Category
Software
-
view
23.646 -
download
2
description
Transcript of 9 anti-patterns for node.js teams
![Page 1: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/1.jpg)
9 anti-patternsfor node.js teams
Jeff Harrell @juxtajeff
![Page 2: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/2.jpg)
• 35 apps live (marketing, signup, account, payments, etc).
• 400 new JavaScript engineers
• 500,000 npm installs per day (internally)
Node first went live on paypal.com in 2013. Since:
Made a good deal of mistakes to learn from
![Page 3: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/3.jpg)
Anti-pattern #1Baggage from your previous technology
![Page 4: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/4.jpg)
• "Node doesn't support x. It won’t work"
• “How do I deal with npm version conflicts?”
• “Can’t let the app restart. It takes too long”
![Page 5: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/5.jpg)
Leave your baggage behind."!
Except when you’re flying
![Page 6: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/6.jpg)
Anti-pattern #2Monolithic applications
![Page 7: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/7.jpg)
• Use an internal npm instance
• Publish modules vs. embedding functionality
• Don’t overload modules – compose them
Prefer different user, credit card and bank modules Avoid a single “shared” module
![Page 8: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/8.jpg)
Build with many blocks, not one."
![Page 9: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/9.jpg)
Anti-pattern #3Googling “How to do x in JavaScript”
![Page 10: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/10.jpg)
• jQuery results dominate search engines
• Understand ES5
• Be aware of what’s coming in ES6
![Page 11: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/11.jpg)
Learn JavaScript before diving in."!
![Page 12: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/12.jpg)
Anti-pattern #4Handling errors
![Page 13: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/13.jpg)
• Use an Error object, not a string
• Throwing is for programmer errors
• Restart on uncaught exception vs ignoring it
![Page 14: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/14.jpg)
Error cases are hard."!
Make sure to deal with them
![Page 15: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/15.jpg)
Anti-pattern #5Wrapping everything in promises
![Page 16: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/16.jpg)
• Use for the right reasons (not throw or waterfall)
• Modules should expose callback interfaces
• Use promises sparingly in hot code
27% of CPU time spent in promise execution
![Page 17: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/17.jpg)
Callbacks."!
Seriously
![Page 18: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/18.jpg)
Anti-pattern #6Git URLs in your package.json
![Page 19: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/19.jpg)
• Git URLs don’t fully leverage semver
• Weird caching issues
• Unstable state (akin to force overwriting in npm)
![Page 20: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/20.jpg)
Publish to npm."!
Set it up internally and use it
![Page 21: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/21.jpg)
Anti-pattern #7Sloppy async code
![Page 22: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/22.jpg)
• Understand control flow patterns
• Don’t create crazy waterfalls
Hoist functions Use promises (appropriately)Use async
• Callback with code afterwards, but no return
if (true) { callback();}fallback();
![Page 23: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/23.jpg)
Use good async patterns."!
Queue funny mis-ordered async sentence
![Page 24: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/24.jpg)
Anti-pattern #8Having node do everything
![Page 25: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/25.jpg)
• SSL termination should be done by nginx
• Heavy encryption is not for node
• Don’t bind directly to port 80/443
“How do I enable gzip?” “How do I add an SSL cert to my app?”
![Page 26: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/26.jpg)
Best tool, meet job."!
![Page 27: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/27.jpg)
Anti-pattern #9Ignoring the node ecosystem
![Page 28: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/28.jpg)
• npm has a wealth of pre-written code
• Get updates from community, e.g. Node Security
• Conferences like this
![Page 29: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/29.jpg)
Embrace your new community."!
Warning: May contain drama
![Page 30: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/30.jpg)
Thanks!"!
Q&A is over drinks later!
![Page 31: 9 anti-patterns for node.js teams](https://reader033.fdocuments.net/reader033/viewer/2022052504/54b868024a7959e9418b488f/html5/thumbnails/31.jpg)
Photo Credits1. https://www.flickr.com/photos/11334694@N00/268023465/
2. https://www.flickr.com/photos/14125773@N00/14205159881/
3. https://www.flickr.com/photos/60364452@N00/3921008904/
4. https://www.flickr.com/photos/83099438@N00/5902730038
5. https://www.flickr.com/photos/82402200@N00/523497824/
6. https://www.flickr.com/photos/48553010@N00/113694992/
7. https://www.flickr.com/photos/46889122@N03/4304137088/
8. https://www.flickr.com/photos/39039882@N00/5189290606/
9. https://www.flickr.com/photos/43145783@N00/1852428153/