学习cnode源码遇到的问题,求大大指导
菜鸡一只 ,大神轻喷
在app.js里声明 var ctrltest = require('./controller/ctrlDepartment')
,执行node app.js报错
carlos[@carlos-virtual-machine](/user/carlos-virtual-machine):~/workspace/nodejs/itsys$ node app.js
connect to undefined error: getaddrinfo ENOTFOUND undefined
注释掉var ctrltest = require('./controller/ctrlDepartment')
后正常,相关代码贴出来了,请各位大大给看看
app.js
var ctrltest = require('./controller/ctrlDepartment')
/controller/ctrlDepartment.js
var Department = require('../proxy').Department;
exports.show = function(){
Department.newAndSave("1","2","3",function(result){
console.log(result);
});
}
/proxy/index.js
exports.Department = require('./department');
/proxy/department.js
var DepartmentModel = require('../model').Deparment;
exports.newAndSave = function (departmentID , departmentName , departmentPosition, callback) {
var DepartmentModel = new DepartmentModel();
DepartmentModel.DepartmentID = departmentID;
DepartmentModel.DepartmentName = departmentName;
DepartmentModel.DepartmentPosition = departmentPosition;
console.log(DepartmentModel);
callback(DepartmentModel);
};
/model/index.js
var mongoose = require('mongoose');
var config = require('../config');
mongoose.connect(config.db, function (err) {
if (err) {
console.error('connect to %s error: ', config.db, err.message);
process.exit(1);
}
});
// models
require('./Department');
exports.Department = mongoose.model('DepartmentModel');
/model/Department.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var DepartmentSchema = new Schema({
DepartmentID : {type : String,default:"default ID"},
DepartmentName : {type : String, default:"default Name"},
DepartmentPosition : {type : String, default:"{'p1','p2','p3'}"},
});
mongoose.model("DepartmentModel", DepartmentSchema);
3 回复