title: ReferenceError: error is not defined
body: <p>ReferenceError: error is not defined in the code:</p>
  
  <pre><code>app.post('/register', function(req, res) {
    var hash = bcrypt.hashSync(req.body.password, bcrypt.genSaltSync(10));
    var user = new User({
      firstName: req.body.firstName,
      lastName: req.body.lastName,
      email: req.body.email,
      password: hash,
    });
    user.save(function(err) {
      if (err) {
        var err = 'Something bad happened, try again!';
        if(err.code === 11000) {
          error = 'That email is already taken, try another.';
        }
        res.render('register.jade', { error: error });
      } else {
        res.redirect('/dashboard');
      }
    });
  });
  </code></pre>
  
  <p>Specifically the error is on this line I believe:</p>
  
  <pre><code>  res.render('register.jade', { error: error });
  </code></pre>
  
  <p>Can anyone tell me how to fix this. I thought I defined it when I put in:</p>
  
  <pre><code>  if(err.code === 11000) {
          error = 'That email is already taken, try another.';
     }
  </code></pre>
  
  <p>The error I received is:</p>
  
  <pre><code>/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:779
        catch(err) { process.nextTick(function() { throw err}); }
                                                         ^
  ReferenceError: error is not defined
      at /Users/darceymckelvey/Documents/auth/app.js:57:44
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/lib/document.js:1747:19
      at handleError (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:40:22)
      at next_ (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:75:26)
      at fnWrapper (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:186:18)
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/lib/model.js:290:15
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/lib/model.js:191:14
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/lib/model.js:135:9
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/lib/collection.js:484:20
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/lib/collection.js:597:14
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:469:9
      at resultHandler (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/lib/bulk/unordered.js:416:5)
      at /Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:778:13
      at Callbacks.emit (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:95:3)
      at null.messageHandler (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:249:23)
      at Socket.&lt;anonymous&gt; (/Users/darceymckelvey/Documents/auth/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:262:22)
  </code></pre>