node js db.get is not a function
<p>I am having this error I can't figure out how to fix;</p>

<pre><code>TypeError: db.get is not a function
routes\boxes.js:20:25
server.js:45:5
</code></pre>

<p><strong>database.js</strong></p>

<pre><code>module.exports = {    
    'url' : 'mongodb://localhost/database'    
};
</code></pre>

<p><strong>server.js</strong></p>

<pre><code>// server.js

// set up ======================================================================
// get all the tools we need
var express  = require('express');
var app      = express();
var port     = process.env.PORT || 8080;
var mongoose = require('mongoose');
var passport = require('passport');
var flash    = require('connect-flash');

var morgan       = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser   = require('body-parser');
var session      = require('express-session');

var db = require('./config/database.js');


// configuration ===============================================================
mongoose.connect(db.url); // connect to our database

require('./config/passport')(passport); // pass passport for configuration

// set up our express application
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser()); // get information from html forms

app.set('view engine', 'ejs'); // set up ejs for templating

// required for passport
app.use(session({ secret: 'secretkeykeykeykey' })); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session

// routes ======================================================================
require('./app/routes/routes')(app, passport); // load our routes and pass in our app and fully configured passport
var boxes = require('./app/routes/boxes');

// Make our db accessible to our router
app.use(function(req,res,next){
    req.db = db;
    next();
});

app.use('/portal', boxes);

// launch ======================================================================
app.listen(port);
console.log('The magic happens on port ' + port);
</code></pre>

<p><strong>boxlist.js</strong></p>

<pre><code>var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var BoxlistSchema = new Schema({
      name: {
           type: String
      },
      //insert your other key of collection
});

module.exports = mongoose.model('Boxlist', BoxlistSchema);
</code></pre>

<p><strong>boxes.js</strong></p>

<pre><code>var express = require('express');
var router = express.Router();
var collection = require('./boxlist');

/*
 * GET boxlist.
 */
router.get('/boxlist', function(req, res) {
    var db = req.db;
    var collection = db.get('boxlist');
    collection.find({},{},function(e,docs){
        res.json(docs);
    });
});

/*
 * POST to addbox.
 */
router.post('/addbox', function(req, res) {
    var db = req.db;
    // var collection = db.get('boxlist');
    db.collection.insert(req.body, function(err, result){
        res.send(
            (err === null) ? { msg: '' } : { msg: err }
        );
    });
});

/*
 * DELETE to deletebox.
 */
router.delete('/deletebox/:id', function(req, res) {
    var db = req.db;
    var collection = db.get('boxlist');
    var boxToDelete = req.params.id;
    collection.remove({ '_id' : boxToDelete }, function(err) {
        res.send((err === null) ? { msg: '' } : { msg:'error: ' + err });
    });
});

module.exports = router;
</code></pre>

<p><strong>global.js</strong></p>

<pre><code>// Boxlist data array for filling in info box
var boxListData = [];

// DOM Ready =============================================================
$(document).ready(function () {

    // Populate the box table on initial page load
    populateTable();

    // Boxname link click
    $('#boxList table tbody').on('click', 'td a.linkshowbox', showBoxInfo);

    // Add Box button click
    $('#btnAddBox').on('click', addBox);

    // Delete Box link click
    $('#boxList table tbody').on('click', 'td a.linkdeletebox', deleteBox);

});

// Functions =============================================================

// Fill table with data
function populateTable() {

    // Empty content string
    var tableContent = '';

    // jQuery AJAX call for JSON
    $.getJSON('/portal/boxlist', function (data) {

        // Stick our box data array into a boxlist variable in the global object
        boxListData = data;

        // For each item in our JSON, add a table row and cells to the content string
        $.each(data, function () {
            tableContent += '&lt;tr&gt;';
            tableContent += '&lt;td&gt;&lt;a href="#" class="linkshowbox" rel="' + this.boxname + '" title="Show Details"&gt;' + this.boxname + '&lt;/a&gt;&lt;/td&gt;';
            tableContent += '&lt;td&gt;' + this.vm + '&lt;/td&gt;';
            tableContent += '&lt;td&gt;&lt;a href="#" class="linkdeletebox" rel="' + this._id + '"&gt;delete&lt;/a&gt;&lt;/td&gt;';
            tableContent += '&lt;/tr&gt;';
        });

        // Inject the whole content string into our existing HTML table
        $('#boxList table tbody').html(tableContent);
    });
};

// Show Box Info
function showBoxInfo(event) {

    // Prevent Link from Firing
    event.preventDefault();

    // Retrieve boxname from link rel attribute
    var thisBoxName = $(this).attr('rel');

    // Get Index of object based on id value
    var arrayPosition = boxListData.map(function (arrayItem) {
        return arrayItem.boxname;
    }).indexOf(thisBoxName);

    // Get our Box Object
    var thisBoxObject = boxListData[arrayPosition];

    //Populate Info Box
    $('#boxInfoName').text(thisBoxObject.fullname);
    $('#boxInfoVm').text(thisBoxObject.vm);
    $('#boxInfoDescription').text(thisBoxObject.description);
    $('#boxInfoVersion').text(thisBoxObject.version);

};

// Add Box
function addBox(event) {
    event.preventDefault();

    // Super basic validation - increase errorCount variable if any fields are blank
    var errorCount = 0;
    $('#addBox input').each(function (index, val) {
        if ($(this).val() === '') {
            errorCount++;
        }
    });

    // Check and make sure errorCount's still at zero
    if (errorCount === 0) {

        // If it is, compile all box info into one object
        var newBox = {
            'boxname': $('#addBox fieldset input#inputBoxName').val(),
            'init': $('#addBox fieldset input#inputBoxInit').val(),
            'vm': $('#addBox fieldset input#inputBoxVm').val(),            
            'description': $('#addBox fieldset input#inputBoxDescription').val(),
            'version': $('#addBox fieldset input#inputBoxVersion').val()
        }

        // Use AJAX to post the object to our addbox service
        $.ajax({
            type: 'POST',
            data: newBox,
            url: '/portal/addbox',
            dataType: 'JSON'
        }).done(function (response) {

            // Check for successful (blank) response
            if (response.msg === '') {

                // Clear the form inputs
                $('#addBox fieldset input').val('');

                // Update the table
                populateTable();

            } else {

                // If something goes wrong, alert the error message that our service returned
                alert('Error: ' + response.msg);

            }
        });
    } else {
        // If errorCount is more than 0, error out
        alert('Please fill in all fields');
        return false;
    }
};

// Delete Box
function deleteBox(event) {

    event.preventDefault();

    // Pop up a confirmation dialog
    var confirmation = confirm('Are you sure you want to delete this box?');

    // Check and make sure the box confirmed
    if (confirmation === true) {

        // If they did, do our delete
        $.ajax({
            type: 'DELETE',
            url: '/portal/deletebox/' + $(this).attr('rel')
        }).done(function (response) {

            // Check for a successful (blank) response
            if (response.msg === '') {} else {
                alert('Error: ' + response.msg);
            }

            // Update the table
            populateTable();

        });

    } else {

        // If they said no to the confirm, do nothing
        return false;

    }

};
</code></pre>

<p><strong>portal.js</strong></p>

<pre><code>&lt;!-- views/profile.ejs --&gt;
&lt;!doctype html&gt;
&lt;html&gt;

&lt;head&gt;
    &lt;title&gt;Vagrant CLI Node API&lt;/title&gt;
    &lt;link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"&gt;
    &lt;link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"&gt;
    &lt;style&gt;
        body {
            padding-top: 80px;
            word-wrap: break-word;
        }
    &lt;/style&gt;
    &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="/javascripts/global.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div class="container"&gt;

        &lt;div class="page-header text-center"&gt;
            &lt;h1&gt;&lt;span class="fa fa-th"&gt;&lt;/span&gt; Portal&lt;/h1&gt;
            &lt;a href="/profile" class="btn btn-default btn-sm"&gt;Profile&lt;/a&gt;
            &lt;a href="/logout" class="btn btn-default btn-sm"&gt;Logout&lt;/a&gt;
        &lt;/div&gt;

        &lt;div class="row"&gt;

            &lt;!-- AVAILABLE BOXES --&gt;
            &lt;div class="col-sm-6"&gt;
                &lt;div id="boxList" class="well"&gt;
                    &lt;h3&gt;&lt;span class="fa fa-th"&gt;&lt;/span&gt; Available Boxes&lt;/h3&gt;

                    &lt;table class="table"&gt;
                        &lt;thead&gt;
                            &lt;tr&gt;
                                &lt;th&gt;Name&lt;/th&gt;
                                &lt;th&gt;Vm&lt;/th&gt;
                                &lt;th&gt;Delete&lt;/th&gt;
                            &lt;/tr&gt;
                        &lt;/thead&gt;
                        &lt;tbody&gt;&lt;/tbody&gt;
                    &lt;/table&gt;

                &lt;/div&gt;
            &lt;/div&gt;

            &lt;!-- BOX INFO --&gt;
            &lt;div class="col-sm-6"&gt;
                &lt;div class="well" id="boxInfo"&gt;
                    &lt;h3&gt;&lt;span class="fa fa-th"&gt;&lt;/span&gt; Box info&lt;/h3&gt;

                    &lt;p&gt;
                        &lt;strong&gt;Select box name for more information&lt;/strong&gt;
                        &lt;br&gt;
                    &lt;/p&gt;

                    &lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; &lt;span id='boxInfoName'&gt;&lt;/span&gt;
                        &lt;br/&gt;&lt;strong&gt;Vm:&lt;/strong&gt; &lt;span id='boxInfoVm'&gt;&lt;/span&gt;
                        &lt;br/&gt;&lt;strong&gt;Description:&lt;/strong&gt; &lt;span id='boxInfoDescription'&gt;&lt;/span&gt;
                        &lt;br/&gt;&lt;strong&gt;Version:&lt;/strong&gt; &lt;span id='boxInfoVersion'&gt;&lt;/span&gt;&lt;/p&gt;

                    &lt;a class="fa fa-plus" href="#"&gt;
                        &lt;i&gt;&lt;/i&gt; start box instance and add to account&lt;/a&gt;

                &lt;/div&gt;
            &lt;/div&gt;

            &lt;!-- ADD NEW BOX --&gt;
            &lt;div class="col-sm-6"&gt;
                &lt;div class="well"&gt;
                    &lt;h3&gt;&lt;span class="fa fa-th"&gt;&lt;/span&gt; Add box&lt;/h3&gt;

                    &lt;p&gt;
                        &lt;strong&gt;Add new box to `available boxes`&lt;/strong&gt;
                        &lt;br&gt;
                    &lt;/p&gt;

                    &lt;form id="addBox" class="form-inline" action="/portal/addbox" method="post"&gt;
                        &lt;fieldset class="form-group"&gt;
                            &lt;input id="inputBoxName" type="text" class="form-control" placeholder="Boxname" /&gt;
                            &lt;input id="inputBoxInit" type="text" class="form-control" placeholder="Init" /&gt;
                            &lt;input id="inputBoxVm" type="text" class="form-control" placeholder="Vm" /&gt;
                            &lt;input id="inputBoxVersion" type="text" class="form-control" placeholder="Description" /&gt;
                            &lt;input id="inputBoxDescription" type="text" class="form-control" placeholder="Version" /&gt;
                            &lt;br&gt;
                            &lt;br&gt;
                            &lt;button type="submit" id="btnAddBox" class="btn btn-primary"&gt;Add Box&lt;/button&gt;
                        &lt;/fieldset&gt;
                    &lt;/form&gt;

                &lt;/div&gt;
            &lt;/div&gt;

        &lt;/div&gt;

    &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>Does anybody know what's going on and how to fix this? My code <em>excludes node_modules</em> <a href="https://dl.dropboxusercontent.com/u/41330678/api.rar" rel="nofollow">link to dropbox</a>
Thanks</p>

<p>PS. Parts of these codes are from this tutorial: <a href="http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/" rel="nofollow">link</a> which can be forked from GitHub: <a href="https://github.com/cwbuecheler/node-tutorial-2-restful-app" rel="nofollow">link</a>. This code works, but I've implemented it into my own application and as far as I know it's now the same code, but I get the error in my app, but not in his app.</p>