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