Friday 2 June 2017

mongoose is not defined

I'm following this tutorial, which creates a To-do list using express and mongo. I am getting the following errors:

body-parser deprecated undefined extended: provide extended option server.js:12:20
C:\todoListApi\api\controllers\todoListController.js:4
var Task = mongoose.model('Tasks');
           ^
ReferenceError: mongoose is not defined
    at Object.<anonymous> (C:\todoListApi\api\controllers\todoListController.js:4:12)
    ...

The body-parser deprecated error I have tried to fix using this post to no avail (although it seems like more of a warning).

The mongoose error doesn't make any sense because mongoose ids defined directly before it:

var mongooose = require('mongoose').Mongoose,
    Task = mongoose.model('Tasks');

But it's also defined in server.js:

var express = require('express'),
    app = express(),
    port = process.env.PORT || 3000,
    mongoose = require('mongoose'),
    Task = require('./api/models/todoListModel'),
    bodyParser = require('body-parser');

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/Tododb');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded(bodyParser.json()));

var routes = require('./api/routes/todoListRoutes');
routes(app);

app.listen(port);

console.log('todo list RESTful API server started on: ' + port)

I changed this from the original tutorial to add .Mongoose because this post said it would work.



via Travis Heeter

No comments:

Post a Comment