节点错误:尝试访问路由/设置时连接ETIMEDOUT

时间:2015-05-23 23:13:19

标签: javascript node.js mongodb

我在Authenticate with NodeJs and JSON web tokens.

上按照本教程指南进行操作

我创建了 server.js config.js 用户模型

我的应用在localhost:3333 上运行正常(我的8080永不运行)。然后我添加了/setup路由来创建用户。

进入/设置应用程序看起来像挂了一段时间后,它就抛出了这个错误:

enter image description here

我的完整server.js文件

// require packages
// ===================================================================
var express    = require('express');
var app        = express();
var bodyParser = require('body-parser');
var morgan     = require('morgan');
var mongoose   = require('mongoose');
var jwt        = require('jsonwebtoken');  // used to create, sign, and verify tokens
var config     = require('./config');      // get our config file
var User       = require('./models/user'); // get our mongoose model


// configuration
// ===================================================================
var port = process.env.PORT || 3333;   // used to create, sign, and verify tokens
mongoose.connect(config.database);     // connect to database
app.set('superSecret', config.secret); // secret variable

// use body parser so we can get info from POST and/or URL parameters
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// use morgan to log requests to the console
app.use(morgan('dev'));


// routes
// ===================================================================

// basic route
app.get('/', function(req, res) {
    res.send('Hello! The API is at http://localhost:' + port + '/api');
});

app.get('/setup', function(req, res) {

    // create a sample user
    var nick = new User({
      name: 'Nick Cerminara',
      password: 'password',
      admin: true
    });

    // save the sample user
    nick.save(function(err) {
      if (err) throw err;
      console.log('User saved successfully');
      res.json({ success: true });
    });
});

// API ROUTES -------------------
// we'll get to these in a second


// start the server
// ===================================================================
app.listen(port);
console.log('Magic happens at http://localhost:' + port);

我的完整配置文件:

module.exports = {
    'secret'   : 'ilovescotchyscotch',
    'database' : 'mongodb://noder:noderauth&54;proximus.modulusmongo.net:27017/so9pojyN'
};

1 个答案:

答案 0 :(得分:1)

看起来数据库不可用。你为什么要尝试使用教程中给出的数据库?您可以在给定的教程中注册自己的数据库,也可以尝试将它放在自己的机器上以进行测试。

相关问题