SlideShare a Scribd company logo
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 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
Real World Lessons On The Anti-Patterns of Node.JS
Real World Lessons On The Anti-Patterns of Node.JS
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 not a funct ion
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 

Real World Lessons On The Anti-Patterns of Node.JS
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
Real World Lessons On The Anti-Patterns of Node.JS


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 Handl ing
@Ben_Hal l 
Ben@BenHal l .me.uk 
Blog.BenHal l .me.uk

More Related Content

PPTX
Node.js Anti Patterns
PPTX
Look Up Mobile Javascript
PDF
CRaSH the shell for the Java Virtual Machine
PDF
Os Alrubaie
ODP
Riereta Node.js session 3 (with notes)
PPTX
Dependencias linux rpm
PPTX
Windows Azure loves OSS
PPTX
CRaSH the shell for the JVM
Node.js Anti Patterns
Look Up Mobile Javascript
CRaSH the shell for the Java Virtual Machine
Os Alrubaie
Riereta Node.js session 3 (with notes)
Dependencias linux rpm
Windows Azure loves OSS
CRaSH the shell for the JVM

Similar to Real World Lessons On The Anti-Patterns of Node.JS (20)

PDF
Node.js Course 1 of 2 - Introduction and first steps
PPTX
Intro to Node.js (v1)
PDF
FITC - Node.js 101
PDF
Treinamento frontend
PDF
9 anti-patterns for node.js teams
PPTX
Irfan maulana nodejs web development
PPTX
PHP Indonesia - Nodejs Web Development
PPTX
Introduction to node.js By Ahmed Assaf
PPTX
Nodejs web service for starters
PDF
Introduction to Node.js
PPTX
Node.js Chapter1
PDF
Nodejs vatsal shah
PPTX
Ecma script
KEY
Dcjq node.js presentation
PDF
Node.js security tour
PPTX
A complete guide to Node.js
PPTX
Overview of Node JS
PPTX
Single Page Applications with AngularJS 2.0
PPTX
Node.js Getting Started &amd Best Practices
PPTX
Intro To Node.js
Node.js Course 1 of 2 - Introduction and first steps
Intro to Node.js (v1)
FITC - Node.js 101
Treinamento frontend
9 anti-patterns for node.js teams
Irfan maulana nodejs web development
PHP Indonesia - Nodejs Web Development
Introduction to node.js By Ahmed Assaf
Nodejs web service for starters
Introduction to Node.js
Node.js Chapter1
Nodejs vatsal shah
Ecma script
Dcjq node.js presentation
Node.js security tour
A complete guide to Node.js
Overview of Node JS
Single Page Applications with AngularJS 2.0
Node.js Getting Started &amd Best Practices
Intro To Node.js
Ad

More from Ben Hall (20)

PPTX
The Art Of Documentation - NDC Porto 2022
PPTX
The Art Of Documentation for Open Source Projects
PPTX
Three Years of Lessons Running Potentially Malicious Code Inside Containers
PPTX
Containers without docker
PPTX
Deploying windows containers with kubernetes
PPTX
The Art of Documentation and Readme.md for Open Source Projects
PPTX
How Secure Are Docker Containers?
PPTX
The Challenges of Becoming Cloud Native
PPTX
Scaling Docker Containers using Kubernetes and Azure Container Service
PPTX
The art of documentation and readme.md
PPTX
Experimenting and Learning Kubernetes and Tensorflow
PPTX
Running .NET on Docker
PPTX
Real World Lessons on the Pain Points of Node.JS Application
PPTX
Tips on solving E_TOO_MANY_THINGS_TO_LEARN with Kubernetes
PPTX
Deploying applications to Windows Server 2016 and Windows Containers
PPTX
The How and Why of Windows containers
PPTX
Lessons from running potentially malicious code inside containers
PPTX
Deploying Windows Containers on Windows Server 2016
PPTX
Learning Patterns for the Overworked Developer
PPTX
Real World Lessons on the Pain Points of Node.js Applications
The Art Of Documentation - NDC Porto 2022
The Art Of Documentation for Open Source Projects
Three Years of Lessons Running Potentially Malicious Code Inside Containers
Containers without docker
Deploying windows containers with kubernetes
The Art of Documentation and Readme.md for Open Source Projects
How Secure Are Docker Containers?
The Challenges of Becoming Cloud Native
Scaling Docker Containers using Kubernetes and Azure Container Service
The art of documentation and readme.md
Experimenting and Learning Kubernetes and Tensorflow
Running .NET on Docker
Real World Lessons on the Pain Points of Node.JS Application
Tips on solving E_TOO_MANY_THINGS_TO_LEARN with Kubernetes
Deploying applications to Windows Server 2016 and Windows Containers
The How and Why of Windows containers
Lessons from running potentially malicious code inside containers
Deploying Windows Containers on Windows Server 2016
Learning Patterns for the Overworked Developer
Real World Lessons on the Pain Points of Node.js Applications
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Monthly Chronicles - July 2025
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation

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

Editor's Notes

  • #9: It’s all about having a good time. If you do blah blah blah you’re going to have a bad time.
  • #28: getTweetsFor("domenic") // promise-returning function .then(function (tweets) { var shortUrls = parseTweetsForUrls(tweets); var mostRecentShortUrl = shortUrls[0]; return expandUrlUsingTwitterApi(mostRecentShortUrl); // promise-returning function }) .then(httpGet) // promise-returning function .then( function (responseBody) { console.log("Most recent link text:", responseBody); }, function (error) { console.error("Error with the twitterverse:", error); } );
  • #31: var repo_url = $(site).find('li[data-tab="repo"]').find('a').attr('href'); var activity_url = $(site).find('li[data-tab="activity"]').find('a').attr('href'); request.get("http://github.com" + repo_url, function(rr, repo_html) { var $_repo = cheerio.load(repo_html); var repo_list = $_repo('.repolist li'); var results = []; repo_list.each(function(ix, p) { var source = true; if($(p).hasClass('fork')) source = false; var repo = { link: "http://github.com" + $(p).find('.repolist-name a').attr('href'), title: $(p).find('.repolist-name').text().clean(), stars: parseInt($(p).find('.stargazers a').text().clean(), 10), is_source: source, language: $(p).find('.language').text()}; if(repo_list.length === (ix + 1)) { request.get("https://github.com" + activity_url, function(err, activity_html) { var $_activity = cheerio.load(activity_html); var repo_list = $_activity('.alert'); var results = []; repo_list.each(function(ix, p) { var repo = {title: $(p).find('.title').text().clean(), actioned_at: $(p).find('.js-relative-date').attr('datetime')}; results.push(repo); if(repo_list.length === (ix + 1)) { data.repositories = results.repo; data.public_activity = results.activity; callback({parser: 'github', id: data.username, profile: data}); } }); }); } }); });
  • #34: var parse_repositories = function(repo_url, callback) { request.get("http://github.com" + repo_url, function(rr, repo_html) { var $_repo = cheerio.load(repo_html); var repo_list = $_repo('.repolist li'); var results = []; repo_list.each(function(ix, p) { var source = true; if($_repo(p).hasClass('fork')) source = false; var repo = { link: "http://github.com" + $_repo(p).find('.repolist-name a').attr('href'), title: $_repo(p).find('.repolist-name').text().clean(), stars: parseInt($_repo(p).find('.stargazers a').text().clean(), 10), is_source: source, language: $_repo(p).find('.language').text()}; if(repo.title !== '') { results.push(repo); } if(repo_list.length === (ix + 1)) { callback(null, results); } }); if(repo_list.length === 0) { callback(null, []); } }); };
  • #37: app.post('/users', function *(request) { var user = new User(request.params); if (yield user.save()) { return JSON.stringify(user); } else { return 422; } });
  • #42: process.on('uncaughtException', function(err) { // handle the error safely console.log(err); });
  • #47: try { var files = yield readdir(dir) } catch (er) { console.error('something happened whilst reading the directory') }