我有一个NodeJS Express项目,它使用mongoose来访问MongoDB数据库。当我在我的本地笔记本电脑上运行应用程序时,它工作正常。我想在Centos VPS主机上运行它。
在没有更改项目中的任何内容的情况下,我在服务器上的app目录中尝试了npm start
,当我尝试使用数据库时出现以下错误:
(AppDir)/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
process.nextTick(function() { throw err; })
^
Error: connect ETIMEDOUT
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
npm ERR! Linux 2.6.32-504.23.4.el6.x86_64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.6
npm ERR! npm v2.11.2
npm ERR! code ELIFECYCLE
npm ERR! App@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the App@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the App package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls App
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! (AppDir)/npm-debug.log
app.js中的代码:
var mongoose = require('mongoose');
var configDB = require('./config/database.js');
mongoose.connect(configDB.url);
//some other app functionality
module.exports = app;
config / database.js中的代码:
module.exports = {
'url' : 'mongodb://(DB URL)'
};
我使用mongoose模型来生成,访问和编辑数据库中的集合。 我无法弄清楚它为什么不能工作,但我想也许这与服务器的IP地址与localhost不同有关?
另外,我已经研究过一个解决方案,有人建议改变/etc/mongod.config
中的一些内容,但由于某种原因我无法找到它......?该文件不存在。