title: TypeError: C:\nodetest1\views\userlist.jade:7
body: <p>I'm getting the above error when I try to pull my user collectionfrom my Mongodb. The relevant code is below, any help as to why this happening would be appreciated.</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>C:\nodetest1\views\userlist.jade:7 5| User List 6| ul &gt; 7| each user, i in userlist 8|      li 9| a(href="mailto:#{user.email}")= user.username Cannot read property 'length' of   undefined
  
  TypeError: C:\nodetest1\views\userlist.jade:7
  5|         User List
  6|     ul
  </code></pre>
  
  <blockquote>
    <p>7|         each user, i in userlist
        8|             li
        9|                 a(href="mailto:#{user.email}")= user.username</p>
  </blockquote>
  
  <pre><code>Cannot read property 'length' of undefined
  at eval (eval at &lt;anonymous&gt; (C:\nodetest1\node_modules\jade\lib\jade.js:172:8),   &lt;anonymous&gt;:50:31)
  at eval (eval at &lt;anonymous&gt; (C:\nodetest1\node_modules\jade\lib\jade.js:172:8),   &lt;anonymous&gt;:93:4)
  at eval (eval at &lt;anonymous&gt; (C:\nodetest1\node_modules\jade\lib\jade.js:172:8), &lt;anonymous&gt;:106:21)
  at res (C:\nodetest1\node_modules\jade\lib\jade.js:173:38)
  at Object.exports.render (C:\nodetest1\node_modules\jade\lib\jade.js:269:10)
  at Object.exports.renderFile (C:\nodetest1\node_modules\jade\lib\jade.js:305:18)
  at View.exports.renderFile [as engine]      (C:\nodetest1\node_modules\jade\lib\jade.js:290:21)
  at View.render (C:\nodetest1\node_modules\express\lib\view.js:76:8)
  at Function.app.render (C:\nodetest1\node_modules\express\lib\application.js:502:10)
  at ServerResponse.res.render (C:\nodetest1\node_modules\express\lib\response.js:777:7)
  </code></pre>
  
  <p><strong>Route</strong></p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET users listing. */
  router.get('/', function(req, res) {
  res.send('respond with a resource');
  });
  module.exports = router;
  </code></pre>
  
  <p>users.js route </p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET users listing. */
  router.get('/', function(req, res) {
  res.send('respond with a resource');
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('static-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  var app = express();
  
  // New Code
  var mongo = require('mongodb');
  var monk = require('monk');
  var db = monk('localhost:27017/nodetest1');
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  app.use(favicon());
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded());
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  // Make our db accessible to our router
  app.use(function(req,res,next){
  req.db = db;
  next();
  });
  
  app.use('/', routes);
  app.use('/users', users);
  
  /// catch 404 and forwarding to error handler
  app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
  });
  
   /// error handlers
  
  // development error handler
  // will print stacktrace
  if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
          message: err.message,
          error: err
      });
  });
  }
  
   // production error handler
   // no stacktraces leaked to user
  app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
      message: err.message,
      error: {}
  });
  });
  module.exports = app;
  </code></pre>
  
  <p><strong>userlist view</strong></p>
  
  <pre><code>extends layout
  
  block content
  h1.
      User List
  ul
      each user, i in userlist
          li
              a(href="mailto:#{user.email}")= user.username
  </code></pre>