connect to undefined error: getaddrinfo ENOTFOUND undefined
发布于 7 年前 作者 CarlosRen 7165 次浏览 最后一次编辑是 6 年前 来自 问答

哪个粑粑见过这个问题?node app.js报的 我都不知道该贴什么代码

8 回复

检查下你的端口是否被占用

@shadow88sky 没有 别的程序用node启动 同一个端口没问题

@CarlosRen 你能换个端口先试试么

@shadow88sky 换了仨都不行~

场景,有没有使用守护进程,以及最基本的贴代码。

@haozxuan


var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

//var departmentDao = require('./routes/mongodb/department');
var Department = require('./model').Department;

var ADsys = require('./routes/auth/ldapAuth');

// view engine setup
//app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'ejs');
app.set('view engine', 'html');
//app.engine('html', require('ejs-mate'));

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// app.get('/save',function(req, res, next){
//   var data = "{ DepartmentID : 'emtity_demo_username', DepartmentName : 'emtity_demo_title', DepartmentPosition:'{'develop','operation','manager'}'}";
//   var result = departmentDao.Save({});
//   res.send(result);
// });
app.get('/save',function(req, res, next){
  var data = "{ DepartmentID : 'emtity_demo_username', DepartmentName : 'emtity_demo_title', DepartmentPosition:'{'develop','operation','manager'}'}";
  Department.newAndSave('emtity_demo_username','emtity_demo_title',"{'develop','operation','manager'}",function(){
    res.send(result);
  });
});

app.get('/ad',function(req, res, next){
  var username = req.param('j_username');
  var password = req.param('j_password');
  // console.log(username);
  // console.log(password);
  if((username!="")&&(password!="")){
    ADsys.adAuth(username,password,function(result){
      // console.log(result);
      res.jsonp({adresult:result});
    });
  }
});

app.get('/ad2',function(req, res, next){
  ADsys.adAuth("F60601","Password1",function(result){
    console.log(result);
    res.send({adresult:result});
  });
});
app.get('/getsysinfo',function(req, res, next){
  var sys = require('./routes/sysconf');
  res.send(sys);
});



// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

app.listen(3000);

module.exports = app;

啥都没有,就是照着cnode的源码在改我的dao层

app.get('/save',function(req, res, next){
  var data = "{ DepartmentID : 'emtity_demo_username', DepartmentName : 'emtity_demo_title', DepartmentPosition:'{'develop','operation','manager'}'}";
  Department.newAndSave('emtity_demo_username','emtity_demo_title',"{'develop','operation','manager'}",function(){
	res.send(result);
  });
});

这是save文件吗?

@haozxuan mongoose save数据 我已经找到报错的文件了

错误1:
var Department = require('./model').Department;
应该是掉用proxy的文件
var Department = require('./proxy').Department;

//model文件
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);

//proxy文件
var EventProxy = require('eventproxy');
var DepartmentModel = require('../model').Deparment;

exports.newAndSave = function (departmentID  , departmentName , departmentPosition, callback) {
 var Department       = new DepartmentModel();

 DepartmentModel.DepartmentID   = departmentID;
 DepartmentModel.DepartmentName   = departmentName;
 DepartmentModel.DepartmentPosition   = departmentPosition;

 if (departmentID) {
   Department.DepartmentID = departmentID;
 }
 Department.save(function (err) {
   callback(err, Department);
 });
};
我觉得是我抄人家代码抄错了 T T
回到顶部