Stuck on getting mongoose, node and express to play nice together

Stuck on getting mongoose, node and express to play nice together

Problem

I am following along with a node.js and express tutorial at DailyJS and have already hit a wall.

In the tutorial it says to do this:

 mongoose = require('mongoose').Mongoose
 db = mongoose.connect('mongodb://localhost/nodepad')

but beforehand he was talking about the code inside the app.js file, so I assume he means for the above code to go inside app.js but I don’t know. At this point I download the nodepad from github to see where he actually put the mongoose code, and I can’t find the above code anywhere in the entire application!

So I am at a loss. Things are already confusing because a default skeleton site made by express is different in many ways to the tutorial, because express has changed a lot in the 2 years since the tutorial was written.

So i’m trying to follow along but I just get really stuck where he says write some code but gives no indication where this code is meant to go.

And afterwards the tutorial says to add a models.js file, and I wonder where this goes, inside the directory perhaps?

(I also understand the above code is outdated and the correct code can be found here, the problem is not the code but where in express its meant to be placed)

Please give me some guidance.

Thanks

Problem courtesy of: Joseph

Solution

Both of those go in app.js. I can give you some more details. I use mongoose and express all the time. I don’t use var mongoose = require('mongoose').Mongoose All I use is var mongoose = require('mongoose')

Let me know if you need any further help.

Solution courtesy of: Stan Cromlish

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *