0

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.

Travis Heeter
  • 13,002
  • 13
  • 87
  • 129

1 Answers1

1

As stated by Jérôme in his comment, your mongoose variable is being defined as mongooose but then being accessed throughout your code as mongoose without the 3rd o.

As for the body parser issue, you don't wrap bodyParser.json() within the bodyParser.urlencoded() middleware. bodyParser.json() is returning its own middleware function that needs to be passed directly to the express server.

app.use(bodyParser.urlencoded({extended: true})
app.use(bodyParser.json())
peteb
  • 18,552
  • 9
  • 50
  • 62