0
當我提交表單請求時,出現錯誤[TypeError: object is not a function]
。 這裏是我的貓鼬代碼:hiren-conf.js
獲取類型錯誤
var auth = require('../auth.js');
var mongoose = require('mongoose');
mongoose.connect(auth['mongodb']);
var authSchema = new mongoose.Schema({
tag: String,
email: String,
username: String,
createdOn: Date,
updatedOn: { type: Date, default: Date.now },
url: String,
password: String,
icon: String
});
var masterPass = new mongoose.Schema({
hash : String,
tag : String,
state: { type: String, default: false}
});
exports.auth = mongoose.model('Auth', authSchema);
exports.master = mongoose.model('Master', masterPass);
和database.js
代碼:
var mongoose = require('mongoose');
var auths = require('../model/hiren-conf');
exports.create = function(req){
var instance = new auths();
if(req.body.tag && req.body.email){
auths.findOne({ 'tag' : req.body.tag , 'email' : req.body.email}, function(err , duplicate){
if (!err){
if(!duplicate){
instance.tag = req.body.tag;
instance.email = req.body.email;
instance.username= req.body.username;
instance.createdOn = Date.now();
instance.url = req.body.url;
instance.password = req.body.password;
instance.save(function(err){
if(!err) console.log('Saved');
});
return "Save";
} else return "Duplicate";
} else console.log(err);
});
}
};
可能存在exports.auth
一個問題,但我不知道。任何想法如何解決這個問題?
我猜的錯誤是從'無功實例= AUTHS新()拋出;''裏面exports.create'。如果'auths'是來自'hiren-conf.js'的'exports',那麼它不會是'function'。它將是一個具有'auth'和'master'屬性的'Object'。也許嘗試'var instance = new auths.auth();'。否則,錯誤發生在哪一行?堆棧跟蹤應該包含文件名和行號。 –
也試過了。新錯誤TypeError:對象#
謝謝它現在工作:) – pyprism