Reputation: 1103
I have a user signup form in my web app and after I upgraded to Mongo 3.6 and Mongoose v5.9.10 I started getting this node server error for my user signup function.
I'm using Node v8.17.0
1) Where is the location of 'events.js'? (I'm not seeing it referenced in the error stack)
2) Is this a problem with something else that I'm not aware of?
I've already tried changing port numbers, rebooting server, deleting node_modules folder and npm install. Nothing is working.
events.js:183
throw er; // Unhandled 'error' event
^
TypeError: respond is not a function
at /home/ec2-user/environment/node_modules/mongoose-unique-validator/index.js:43:9
at /home/ec2-user/environment/node_modules/mongoose/lib/model.js:4850:16
at /home/ec2-user/environment/node_modules/mongoose/lib/model.js:4850:16
at /home/ec2-user/environment/node_modules/mongoose/lib/helpers/promiseOrCallback.js:24:16
at /home/ec2-user/environment/node_modules/mongoose/lib/model.js:4873:21
at _hooks.execPost (/home/ec2-user/environment/node_modules/mongoose/lib/query.js:4379:11)
at /home/ec2-user/environment/node_modules/kareem/index.js:135:16
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Here is the function that runs right before this error is thrown:
UserSchema.plugin(uniqueValidator);
/**
* Hook a pre save method to hash the password
*/
UserSchema.pre('save', function(next) {
console.log("save");
if (this.password && this.password.length > 0) {
console.log("hashing password");
this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
this.password = this.hashPassword(this.password);
}
next();
});
Upvotes: 0
Views: 137
Reputation: 1103
The issue is that the mongoose-unique-validator
module was out of date, and causing the error with the latest versions of MongoDB and Mongoose. Thank you to @ambianBeing for the tip.
I did:
npm install --save mongoose-unique-validator@latest
to make the problem go away.
Upvotes: 1