SlideShare une entreprise Scribd logo
1  sur  85
NODE.JS APPLICATIONS
BUILDING SCALABLE AND DEPENDABLE JAMUND FERGUSON
InfoQ.com: News & Community Site
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
enterprise-nodejs-apps
• Over 1,000,000 software developers, architects and CTOs read the site world-
wide every month
• 250,000 senior developers subscribe to our weekly newsletter
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• 2 dedicated podcast channels: The InfoQ Podcast, with a focus on
Architecture and The Engineering Culture Podcast, with a focus on building
• 96 deep dives on innovative topics packed as downloadable emags and
minibooks
• Over 40 new content items per week
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon London
www.qconlondon.com
The Mystery of the
Missing Stack Trace🕵
THE MYSTERY OF THE MISSING STACK TRACE
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
    at ServerResponse.header (/web/mynodeapp/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/web/mynodeapp/node_modules/express/lib/response.js:170:12)
    at ServerResponse.res.send (/web/mynodeapp/node_modules/pplogger/index.js:225:18)
    at done (/web/mynodeapp/node_modules/express/lib/response.js:1004:10)
    at Stub.callback (/web/mynodeapp/node_modules/adaro/lib/engine.js:137:22)
    at Stub.flush (/web/mynodeapp/pp/node_modules/dustjs-linkedin/lib/dust.js:513:10)
    at Chunk.end (/web/mynodeapp/node_modules/dustjs-linkedin/lib/dust.js:612:15)
    at /web/mynodeapp/node_modules/adaro/lib/patch/index.js:89:53
    at /web/mynodeapp/node_modules/adaro/lib/reader/js.js:39:13
    at /web/mynodeapp/node_modules/engine-munger/lib/munger.js:85:13
    at /web/mynodeapp/node_modules/engine-munger/lib/cache.js:65:13
    at /web/mynodeapp/node_modules/graceful-fs/graceful-fs.js:78:16
    at /web/mynodeapp/node_modules/async-listener/glue.js:188:31
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
😢
We had no idea why or where our apps
were failing
WHAT CAN WE DO?
▸ Compare a diff between last known working code
▸ Look through other logs for more information (nginx logs, access logs, etc)
▸ Look at system metrics (is there a memory leak or CPU spike?)
▸ Add console.log statements somewhere???
▸ Advanced debugging techniques (post-mortem debugging, heapdumps, etc.)
THE MYSTERY OF THE MISSING STACK TRACE
DECRYPT RETURNS A PROMISE
ADDUSER EXPECTS A STRING
LOG EXPECTS A SMALL OBJECT OR A STRING
💣
THE MYSTERY OF THE MISSING STACK TRACE
LESSONS LEARNED
▸ We need better static analysis
▸ We need better debugging tools
▸ We need a consistent way to handle errors
▸ We need to better understand our logging & monitoring
💣
FLOWTYPE & ESLINT
STATIC ANALYSIS WITH
TYPE CHECKING COULD HAVE CAUGHT
THAT BUG WITH 2-LINES OF CODE
STATIC ANALYSIS
STATIC ANALYSIS
PREVENTING BUGS WITH TYPES
STATIC ANALYSIS
PREVENTING BUGS WITH TYPES
STATIC ANALYSIS
FLOW WON’T LET THAT SLIDE
STATIC ANALYSIS
WHY ADD TYPES TO YOUR JS?
▸ Prevents large % of bugs
▸ Helps surface architectural problems
▸ Both Flow and TypeScript are well maintained, high quality tools
▸ Both syntaxes are light-weight and easy to use
▸ Both allow for gradual adoption
🙋 🍩🚫
Type systems have a lot in common with linters
Each JS File Parser (Acorn) Abstract Syntax Tree (AST) Rules
Warning
Success
Errors
Architecture of JavaScript Linter (ESLint)
Linters can only think about one file at a time
All Your JS FilesFlow
Types & Relationships Graph
Architecture of JavaScript Type System (Flow)
Single JS File
Warning
Success
Errors
Flow
Graph
COULD A LINTER HAVE HELPED
US WITH OUR MYSTERY BUG?
STATIC ANALYSIS
STATIC ANALYSIS
STATIC ANALYSIS
STATIC ANALYZERS AND FORMATTERS ARE PRETTY COOL
FlowType ESLint Prettier
Unfortunately, we still get bugs from time to time
INSPECTOR MODULE
DEBUGGING USING THE
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
SETTING UP A DEBUG MODE
TURN IT ON
TURN IT OFF
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
Set Breakpoint
THE BUILT-IN INSPECTOR MODULE
PAUSE ON UNCAUGHT EXCEPTIONS
THE BUILT-IN INSPECTOR MODULE
PAUSE ON CAUGHT EXCEPTIONS
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
Don’t try this in production


STOP
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
THE BUILT-IN INSPECTOR MODULE
https://chromedevtools.github.io/devtools-protocol/
THE BUILT-IN INSPECTOR MODULE
Default Node Error
Inspector Based Error
DEBUGGING NODE.JS APPS
FIND A DEBUGGING APPROACH THAT
WORKS FOR YOU AND YOUR TEAM
ASYNC/AWAIT
ERROR HANDLING USING
ERROR HANDLING WITH ASYNC/AWAIT
Errors thrown inside async
functions get converted into
rejected Promises
💡
ERROR HANDLING WITH ASYNC/AWAIT
Async Middleware Pattern
ERROR HANDLING WITH ASYNC/AWAIT
T H I S I S P R E T T Y N I C E
ERROR HANDLING WITH ASYNC/AWAIT
B U T W E D O N ’ T A C T U A L LY C AT C H I T 💣
E R R O R S W I L L B U B B L E U P
ERROR HANDLING WITH ASYNC/AWAIT
💥
ERROR HANDLING WITH ASYNC/AWAIT
PASS IN YOUR ASYNC MIDDLEWARE
RETURN A STANDARD MIDDLEWARE FUNCTION
CATCH ANY ERRORS
PASS THOSE TO THE EXPRESS ERROR HANDLER
EXECUTE THE ASYNC MIDDLEWARE
APPLY AS NEEDED
ERROR HANDLING WITH ASYNC/AWAIT
💥
Make it easy for your engineers

to do the right thing
ERROR HANDLING WITH ASYNC/AWAIT
Custom Error Classes
CUSTOM ERRORS
CUSTOM ERRORS
CUSTOM ERRORS
1.
2.
3.
CUSTOM ERRORS
CUSTOM ERRORS
CUSTOM ERRORS
CUSTOM ERRORS
SUMMARY
▸ Don’t use object literals or strings for errors (missing stack trace)
▸ Use the Error built-in object
▸ Subclass Error to add statusCodes or to convert error codes into user-
friendly error messages for localization, etc
▸ We basically have one error class per micro-service to handle parsing the
errors out of the response….
The Mystery of the
Client-Side Errors)
THE MYSTERY OF THE CLIENT-SIDE ERRORS
CLIENT-SIDE MONITORING
BUTTON DOESN’T WORK
REAL ISSUE USUALLY IN DEV TOOLS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
CLIENT-SIDE MONITORING
window.onerror = function (msg, url, line, col, error) {

// 1. clean up the data

// 2. log to server w/AJAX or sendBeacon() API

}
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE NOTICED A SPIKE DURING DEPLOY
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE CONGRATULATED OURSELVES…THEN ACTUALLY LOOKED INTO THE BUG
🏆 😮
THE MYSTERY OF THE CLIENT-SIDE ERRORS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE HAVE A LOT OF SERVERS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE HAVE A LOT OF SERVERS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE HAVE A LOT OF SERVERS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE HAVE A LOT OF SERVERS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
WE HAVE A LOT OF SERVERS
THE MYSTERY OF THE CLIENT-SIDE ERRORS
UI Code
Server code
A
B
THE MYSTERY OF THE CLIENT-SIDE ERRORS
ROLLING BACK MADE THINGS WORSE
THE MYSTERY OF THE CLIENT-SIDE ERRORS
LESSONS LEARNED
▸ UI is a huge monitoring blind-spot
▸ Be aware of how the deploy process affects users
▸ Try to make your code changes backwards compatible
▸ Consider separating UI and server deploys
BUILDING SCALABLE AND DEPENDABLE NODE.JS APPLICATIONS
▸Use static analysis (including types) to catch bugs early
▸Have a plan for debugging apps in production
▸Adopt a consistent approach to error handling
▸Know how to access all of your logs
▸Don’t forget to monitor client-side errors
THE END
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
enterprise-nodejs-apps

Contenu connexe

Plus de C4Media

Plus de C4Media (20)

Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven Utopia
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL Database
 
A Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinA Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with Brooklin
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Enterprise Node.JS Apps in 2018

  • 1. NODE.JS APPLICATIONS BUILDING SCALABLE AND DEPENDABLE JAMUND FERGUSON
  • 2. InfoQ.com: News & Community Site Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ enterprise-nodejs-apps • Over 1,000,000 software developers, architects and CTOs read the site world- wide every month • 250,000 senior developers subscribe to our weekly newsletter • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • 2 dedicated podcast channels: The InfoQ Podcast, with a focus on Architecture and The Engineering Culture Podcast, with a focus on building • 96 deep dives on innovative topics packed as downloadable emags and minibooks • Over 40 new content items per week
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon London www.qconlondon.com
  • 4. The Mystery of the Missing Stack Trace🕵
  • 5. THE MYSTERY OF THE MISSING STACK TRACE Error: Can't set headers after they are sent.     at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)     at ServerResponse.header (/web/mynodeapp/node_modules/express/lib/response.js:767:10)     at ServerResponse.send (/web/mynodeapp/node_modules/express/lib/response.js:170:12)     at ServerResponse.res.send (/web/mynodeapp/node_modules/pplogger/index.js:225:18)     at done (/web/mynodeapp/node_modules/express/lib/response.js:1004:10)     at Stub.callback (/web/mynodeapp/node_modules/adaro/lib/engine.js:137:22)     at Stub.flush (/web/mynodeapp/pp/node_modules/dustjs-linkedin/lib/dust.js:513:10)     at Chunk.end (/web/mynodeapp/node_modules/dustjs-linkedin/lib/dust.js:612:15)     at /web/mynodeapp/node_modules/adaro/lib/patch/index.js:89:53     at /web/mynodeapp/node_modules/adaro/lib/reader/js.js:39:13     at /web/mynodeapp/node_modules/engine-munger/lib/munger.js:85:13     at /web/mynodeapp/node_modules/engine-munger/lib/cache.js:65:13     at /web/mynodeapp/node_modules/graceful-fs/graceful-fs.js:78:16     at /web/mynodeapp/node_modules/async-listener/glue.js:188:31     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
  • 7. We had no idea why or where our apps were failing
  • 8. WHAT CAN WE DO? ▸ Compare a diff between last known working code ▸ Look through other logs for more information (nginx logs, access logs, etc) ▸ Look at system metrics (is there a memory leak or CPU spike?) ▸ Add console.log statements somewhere??? ▸ Advanced debugging techniques (post-mortem debugging, heapdumps, etc.) THE MYSTERY OF THE MISSING STACK TRACE
  • 9.
  • 10.
  • 11. DECRYPT RETURNS A PROMISE ADDUSER EXPECTS A STRING LOG EXPECTS A SMALL OBJECT OR A STRING
  • 12. 💣
  • 13. THE MYSTERY OF THE MISSING STACK TRACE LESSONS LEARNED ▸ We need better static analysis ▸ We need better debugging tools ▸ We need a consistent way to handle errors ▸ We need to better understand our logging & monitoring 💣
  • 14. FLOWTYPE & ESLINT STATIC ANALYSIS WITH
  • 15. TYPE CHECKING COULD HAVE CAUGHT THAT BUG WITH 2-LINES OF CODE STATIC ANALYSIS
  • 19. STATIC ANALYSIS WHY ADD TYPES TO YOUR JS? ▸ Prevents large % of bugs ▸ Helps surface architectural problems ▸ Both Flow and TypeScript are well maintained, high quality tools ▸ Both syntaxes are light-weight and easy to use ▸ Both allow for gradual adoption
  • 20.
  • 22. Type systems have a lot in common with linters
  • 23. Each JS File Parser (Acorn) Abstract Syntax Tree (AST) Rules Warning Success Errors Architecture of JavaScript Linter (ESLint)
  • 24. Linters can only think about one file at a time
  • 25. All Your JS FilesFlow Types & Relationships Graph Architecture of JavaScript Type System (Flow) Single JS File Warning Success Errors Flow Graph
  • 26. COULD A LINTER HAVE HELPED US WITH OUR MYSTERY BUG?
  • 29. STATIC ANALYSIS STATIC ANALYZERS AND FORMATTERS ARE PRETTY COOL FlowType ESLint Prettier
  • 30. Unfortunately, we still get bugs from time to time
  • 33.
  • 34. THE BUILT-IN INSPECTOR MODULE SETTING UP A DEBUG MODE TURN IT ON TURN IT OFF
  • 36. THE BUILT-IN INSPECTOR MODULE Set Breakpoint
  • 37. THE BUILT-IN INSPECTOR MODULE PAUSE ON UNCAUGHT EXCEPTIONS
  • 38. THE BUILT-IN INSPECTOR MODULE PAUSE ON CAUGHT EXCEPTIONS
  • 43. Don’t try this in production 
 STOP
  • 46. THE BUILT-IN INSPECTOR MODULE https://chromedevtools.github.io/devtools-protocol/
  • 47. THE BUILT-IN INSPECTOR MODULE Default Node Error Inspector Based Error
  • 48. DEBUGGING NODE.JS APPS FIND A DEBUGGING APPROACH THAT WORKS FOR YOU AND YOUR TEAM
  • 50. ERROR HANDLING WITH ASYNC/AWAIT
  • 51. Errors thrown inside async functions get converted into rejected Promises 💡
  • 52. ERROR HANDLING WITH ASYNC/AWAIT
  • 54. ERROR HANDLING WITH ASYNC/AWAIT T H I S I S P R E T T Y N I C E
  • 55. ERROR HANDLING WITH ASYNC/AWAIT B U T W E D O N ’ T A C T U A L LY C AT C H I T 💣 E R R O R S W I L L B U B B L E U P
  • 56. ERROR HANDLING WITH ASYNC/AWAIT 💥
  • 57. ERROR HANDLING WITH ASYNC/AWAIT PASS IN YOUR ASYNC MIDDLEWARE RETURN A STANDARD MIDDLEWARE FUNCTION CATCH ANY ERRORS PASS THOSE TO THE EXPRESS ERROR HANDLER EXECUTE THE ASYNC MIDDLEWARE APPLY AS NEEDED
  • 58. ERROR HANDLING WITH ASYNC/AWAIT 💥
  • 59. Make it easy for your engineers
 to do the right thing
  • 60. ERROR HANDLING WITH ASYNC/AWAIT
  • 68. CUSTOM ERRORS SUMMARY ▸ Don’t use object literals or strings for errors (missing stack trace) ▸ Use the Error built-in object ▸ Subclass Error to add statusCodes or to convert error codes into user- friendly error messages for localization, etc ▸ We basically have one error class per micro-service to handle parsing the errors out of the response….
  • 69. The Mystery of the Client-Side Errors)
  • 70. THE MYSTERY OF THE CLIENT-SIDE ERRORS CLIENT-SIDE MONITORING BUTTON DOESN’T WORK REAL ISSUE USUALLY IN DEV TOOLS
  • 71. THE MYSTERY OF THE CLIENT-SIDE ERRORS CLIENT-SIDE MONITORING window.onerror = function (msg, url, line, col, error) {
 // 1. clean up the data
 // 2. log to server w/AJAX or sendBeacon() API
 }
  • 72. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE NOTICED A SPIKE DURING DEPLOY
  • 73. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE CONGRATULATED OURSELVES…THEN ACTUALLY LOOKED INTO THE BUG 🏆 😮
  • 74. THE MYSTERY OF THE CLIENT-SIDE ERRORS
  • 75. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE HAVE A LOT OF SERVERS
  • 76. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE HAVE A LOT OF SERVERS
  • 77. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE HAVE A LOT OF SERVERS
  • 78. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE HAVE A LOT OF SERVERS
  • 79. THE MYSTERY OF THE CLIENT-SIDE ERRORS WE HAVE A LOT OF SERVERS
  • 80. THE MYSTERY OF THE CLIENT-SIDE ERRORS UI Code Server code A B
  • 81. THE MYSTERY OF THE CLIENT-SIDE ERRORS ROLLING BACK MADE THINGS WORSE
  • 82. THE MYSTERY OF THE CLIENT-SIDE ERRORS LESSONS LEARNED ▸ UI is a huge monitoring blind-spot ▸ Be aware of how the deploy process affects users ▸ Try to make your code changes backwards compatible ▸ Consider separating UI and server deploys
  • 83. BUILDING SCALABLE AND DEPENDABLE NODE.JS APPLICATIONS ▸Use static analysis (including types) to catch bugs early ▸Have a plan for debugging apps in production ▸Adopt a consistent approach to error handling ▸Know how to access all of your logs ▸Don’t forget to monitor client-side errors
  • 85. Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ enterprise-nodejs-apps