所以我已经通过git将我的express / mongodb应用程序部署到我的Azure Web App,当我打开应用程序的链接时,它会继续加载并显示黑页,我的路由不起作用,但是静态文件仅加载精细。 所以我去看日志,我得到了这个。
D:\home\site\wwwroot\node_modules\mongodb\lib\server.js:236
process.nextTick(function() { throw err; })
^
MongoError: server 127.0.0.1:3000 sockets closed
at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\topologies\server.js:330:47)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:105:12)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\connection.js:145:12)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at TCP._onclose (net.js:469:12)
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\4.2.3\\node.exe" "D:\\Program Files (x86)\\npm\\3.5.1\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.2.3
npm ERR! npm v3.5.1
npm ERR! code ELIFECYCLE
npm ERR! cinemat_iq@0.9.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cinemat_iq@0.9.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cinemat_iq 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 information on how to open an issue for this project with:
npm ERR! npm bugs cinemat_iq
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls cinemat_iq
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\home\site\wwwroot\npm-debug.log
所以这些问题似乎出现在mongodb的连接命令中,我目前将其作为
mongoose.connect('mongodb://127.0.0.1:3000/myapp');
我已尝试更改为localhost而不是127.0.0.1,并尝试使用其他端口,但都导致了同样的错误。
在一些谷歌搜索/堆栈溢出后,似乎我需要删除mongodb中的“锁定文件”,然后修复/重启mongodb服务。 问题是我无法使用Azure控制台(基于Windows)找到此文件,并且我无法运行任何mongo或mongod命令(它不被识别为内部或外部命令)。
那么我该怎么做让我的应用程序在Azure上运行?
答案 0 :(得分:0)
我认为Azure App Service环境中存在本地mongoDB,尝试更改为连接到远程数据库(例如Azure虚拟机上的mongoDB主机)应该解决您的问题。
答案 1 :(得分:0)
据我所知,Azure WebApps上没有直接提供任何数据库。所以问题是由于地址localhost或你的webapp的127.0.0.1
没有mongodb实例,而不是MongoDB连接字符串不正确。
您可以尝试在Azure上创建MongoDB实例,并复制连接字符串以更改代码mongoose.connect('<the remote connection string>')
。
作为参考,您可以参考文档Announcing New MongoDB Instances on Microsoft Azure了解MongoDB on Azure
以及如何开始使用。
答案 2 :(得分:0)
您可以按照post进行操作:
所有QuickStart部分