const mongo = require('mongodb').MongoClient;
)现在我们想要连接到我们的数据库,然后开始侦听请求。这样做的目的是在连接数据库之前或者出现数据库错误时不允许请求。要实现此目的,您需要在以下内容中包含序列化和应用程序侦听器: mongo.connect(process.env.DATABASE,(err,db)=> { if(错误){ console.log('数据库错误:'+错误); } else { console.log('成功的数据库连接');您现在可以在deserializeUser中取消注释该块并删除您的//serialization and app.listen
}});
done(null, null)
。确保将.env文件中的DATABASE设置为数据库的连接字符串(例如: DATABASE=mongodb://admin:pass@mlab.com:12345/my-project
)。您可以在mLab上设置免费数据库。恭喜 - 您已完成序列化设置!当您认为自己已经做对时,请提交您的页面。如果您遇到错误,可以在这里查看到目前为止完成的项目。 done(null, null)
'
testString: 'getUserInput => $.get(getUserInput("url")+ "/_api/server.js") .then(data => { assert.notMatch(data, /null,( |)null/gi, "The callback in deserializeUser of (null, null) should be completely removed for the db block uncommented out"); }, xhr => { throw new Error(xhr.statusText); })'
```