0
的特性“多元化”我刚开始学习和的NodeJS我一直在试图建立一个架构来存储电子邮件和密码,但是当我开始server.js我得到这个猫鼬错误:无法读取空
d:\Make your CV\node_modules\mongoose\lib\index.js:357
ion' in schema.options)) schema.options.pluralization = this.options.pluraliza
^
TypeError: Cannot read property 'pluralization' of null
at Mongoose.model (d:\Make your CV\node_modules\mongoose\lib\index.js:357:88)
at Object.<anonymous> (d:\Make your CV\makecv.js:19:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
,这是makecv.js
var express = require ('express');
var app = express();
var ECT = require('ect');
var ectRenderer = ECT({ watch: true, root: __dirname + '/views', ext : '.ect' });
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/sam');
var db = mongoose.Connection();
var UserSchema = mongoose.Schema({
email : String,
password : String
});
// create the model for users
var User = mongoose.model('User', UserSchema); //line 19
app.use(bodyParser.urlencoded({ extended: false })) //line 21
app.use(bodyParser.json())
app.set('view engine', 'ect');
app.engine('ect', ectRenderer.render);
app.post('/signup', function(req, res){
var email = req.body.email.toLowerCase();
var password = req.body.password;
var user = new User();
user.email = email;
bcrypt.hash(password, null, null, function(err, hpassword) {
// Store hash in your password DB.
user.password = hpassword;
});
user.save(function(err, user){
if(err) throw err;
res.redirect('/');
});
});
app.listen(8080);
我知道代码是怎样的一个烂摊子,但我仍然在学习。
什么是'var db = mongoose.Connection();'? – Barno