我试图启动服务器,但我收到错误:
Error: failed to connect to [localhost:27017]
at null.<anonymous> (C:\node\project\node_modules\mongoose\node_modules\mong
odb\lib\mongodb\connection\server.js:549:74)
at emit (events.js:106:17)
at null.<anonymous> (C:\node\project\node_modules\mongoose\node_modules\mong
odb\lib\mongodb\connection\connection_pool.js:150:15)
at emit (events.js:98:17)
at Socket.<anonymous> (C:\node\project\node_modules\mongoose\node_modules\mo
ngodb\lib\mongodb\connection\connection.js:533:10)
at Socket.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:419:13)
这是我的代码:
var debug = require('debug')('project');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
当我使用&#34; npm start&#34; - 服务器正在起步一秒钟,但实际上它正在下降..
答案 0 :(得分:4)
通过从命令行运行mongod
来确保您的服务器已启动。