0

我正在尝试来自 Jump start node.js(第 1 章身份验证)的示例。我编写了所有程序并创建了第 1 章所需的所有文件和文件夹。对于那些不知道第 1 章是关于使用 mongolab 云服务的人。

表单.html

<form action="/signup" method="post">
  <div>
    <label>Username:</label>
    <input type="text" name="username"/><br/>
  </div>
  <div>
    <label>Password:</label>
    <input type="password" name="password"/>
  </div>
  <div><input type="submit" value="Sign Up"/></div>
</form>`

库/db.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.mongoose = mongoose;
module.exports.Schema = Schema;
// Connect to cloud database

var username = "user"
var password = "password";
var address = ' @dbh42.mongolab.com:27427/nockmarket';
connect();
// Connect to mongo
function connect() {
  var url = 'mongodb://' + username + ':' + password + address;
  console.log('[*] not reaching here');
  mongoose.connect(url);
}
function disconnect() {mongoose.disconnect()}

模型/User.js

var db = require('../lib/db');
var UserSchema = new db.Schema({
  username : {type: String, unique: true}
  , password : String
})
var MyUser = db.mongoose.model('User', UserSchema);
// Exports
module.exports.addUser = addUser;
// Add user to database
function addUser(username, password, callback) {
  var instance = new MyUser();
  instance.username = username;
  instance.password = password;
  instance.save(function (err) {
    if (err) {
      callback(err);
    }
    else {
      callback(null, instance);
    }
  });
}

当我总结表单应用程序挂起并且它没有调用 connect() 函数女巫连接到 mongolab 它只是等待完成但没有任何反应。

谢谢,

4

0 回答 0