Callback Hell

Avoid the callback triangle of doom with three simple rules:

  1. keep your code shallow
  2. modularize
  3. handle every single error

example:

 var fs = require('fs')

 fs.readFile('/Does/not/exist', handleFile)

 function handleFile (error, file) {
   if (error) return console.error('Uhoh, there was an error', error)
   // otherwise, continue on and use `file` in your code
 }