I have been looking at code (https://github.com/cmarin/MongoDB-Node-Express-Blog) to learn NodeJS, Express, Mongoose, and I am having trouble importing a ‘Poll’ function from my ‘models.js’ file, particularly the ‘save’ function.
I am getting the following error:
500 TypeError: Object function (){} has no method 'save'
It occurs on line 54 of my app.js. I am unable to save a new Poll because it cannot find the function:
https://github.com/kelper/Poll/blob/master/app.js
Here is my models file, and the save function is on line 62:
https://github.com/kelper/Poll/blob/master/models.js
One other quick question. How can I exclude files from being committed? I keep committing swap files and such to my repo.
If you see anything else wrong with my code, please tell me. I know one person mentioned that my naming conventions are confusing. How should I be naming my variables?
PollModel is a function constructor, you want to create an object.
var PollModel = require('./models').PollModel;is wrongvar pollModel = new (require('./models').PollModel);is right.