简体   繁体   English

如何将Mean.js Web应用程序部署到heroku,数据库托管在mlab?

[英]How to deploy a mean.js web app to heroku, with the database hosted at mlab?

Please tell me the exact step by step instructions. 请告诉我确切的分步说明。 Suppose I just newly cloned and built my new MEAN.JS application. 假设我刚刚克隆并构建了新的MEAN.JS应用程序。 It is running fine on my localhost. 它在我的本地主机上运行良好。

And now I have created a new database at mlabs. 现在,我在mlabs创建了一个新数据库。 Got the URI, user and passkey for that database from mlabs. 从mlabs获得了该数据库的URI,用户和密码。

Now please tell me how to proceed to successfully deploy this application on heroku. 现在,请告诉我如何继续在heroku上成功部署此应用程序。


What I've tried : --- 我尝试过的--

I changed the production.js file, even the development.js file located in the env folder. 我更改了production.js文件,甚至更改了位于env文件夹中的development.js文件。

Ive done this in those two files. 我已经在这两个文件中完成了此操作。 After doing this, when I run the app on my localhost, it successfully runs and the database gets connected to mLabs. 完成此操作后,当我在本地主机上运行该应用程序时,该应用程序成功运行,并且数据库已连接到mLabs。 But in heroku, it gives an application error. 但是在heroku中,它给出了应用程序错误。 I am also including the heroku logs. 我还包括heroku日志。

  db: {
uri: "mongodb://xxx:mLabxxx@ds023624.mlab.com:23624/project",
options: {
  user: 'username',
  pass: 'password'
},
// Enable mongoose debug mode
debug: process.env.MONGODB_DEBUG || false

} }

HEROKU LOGS 英雄日志

According to the logs, i think it is not able to connect to the database. 根据日志,我认为它无法连接到数据库。 See this error : -- 看到此错误:-

 [MongoError: connect ECONNREFUSED 127.0.0.1:27017]

Heroku runs your app on production environment as default, so you should check the production configuration. Heroku默认在生产环境上运行您的应用程序,因此您应检查生产配置。

Taking the repository you linked as a base, in this line it gets the DB url from environment variables called MONGOHQ_URL or MONGODB_URI , so you should either add them to Heroku with the MongoLab URI or replace on the code with the variable name you want (make sure it is created on Heroku too). 以您链接的存储库为基础,在这一行中,它从名为MONGOHQ_URLMONGODB_URI环境变量获取数据库URL,因此您应使用MongoLab URI 将它们添加到Heroku或将代码替换为所需的变量名(确保它也是在Heroku上创建的)。

If it works on your localhost and not in Heroku, it means that the production config is wrong on Heroku, you should also make sure you are pushing the changes to the production config file to Heroku repository too. 如果它在您的本地主机上运行而不在Heroku上运行,则意味着生产配置在Heroku上错误,还应确保将对生产配置文件的更改也推送到Heroku存储库。 If you want to test on Heroku using the development environment, you can change this setting . 如果要使用开发环境在Heroku上进行测试,则可以更改此设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM