我通过nodejs进行用户身份验证。 TypeError:Oject不是像这样抛出错误的函数
user.js的
// get an instance of mongoose and mongoose.Schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// set up a mongoose model and pass it using module.exports
module.exports = mongoose.model('User', new Schema({
name: String,
password: String,
admin: Boolean
}));
server.js
User = require('./models/user');
app.get('/setup', function (req, res) {
// create a sample user
var nick = new User({ // In this line throwing error Object is not a function.
name: 'Nick Cerminara',
password: 'password',
admin: true
});
// save the sample user
nick.save(function (err) {
if (err) throw err;
console.log('User saved successfully');
res.json({
success: true
});
});
});