将nodejs应用程序部署到Heroku [英] Deploy nodejs application to Heroku
问题描述
我有一个存储库克隆 https://github.com/ibnclaudius / express-mongoose-es6-rest-api ,我想部署到Heroku。在部署中,指令编写如下:
#编译为ES5
1. npm run build or gulp
#上传dist /到你的服务器
2. scp -rp dist / user @ dest:/ path
#只安装生产依赖项
3. npm i --production
#使用任何流程管理器启动您的服务
4. pm2 start dist / index.js
在生产中,您需要确保您的服务器始终处于运行状态,因此您理想情况下应使用此处推荐的任何流程管理器。我们b $ b推荐pm2,因为它有几个有用的功能,比如它可以是
,配置为在系统重启时自动启动您的服务。
我不知道如何继续。我如何按照建议进行部署,但在Heroku环境中部署?我尝试通过Heroku CLI发送,但没有成功。
我尝试过:
npm run build
cd dist /
git init
heroku git:remote -a农场公鸡
git add。
git commit -amInício
git push heroku master
应用程序日志:
2016-10-09T23:33:33.364424 + 00:00 app [web.1]:npm ERR!您可以通过以下方式获得
的信息:
< .1]:npm ERR!或者,如果这不是
可用,您可以通过以下方式获取他们的信息:
2016-10-09T23:33:33.364968 + 00:00 app [web .1]:npm ERR! npm owner ls
express-mongoose-es6-rest-api
2016-10-09T23:33:33.365079 + 00:00 app [web.1] :npm ERR!上面可能还有
额外的日志输出。
2016-10-09T23:33:33.368518 + 00:00 app [web.1]:
2016-10-09T23:33:33.368965 + 00:00 app [web.1]:npm ERR!请包含
以下任何支持请求的文件:
2016-10-09T23:33:33.369132 + 00:00 app [web.1]:npm ERR!
/app/npm-debug.log
2016-10-09T23:33:33.469487 + 00:00 heroku [web.1 ]:从
开始崩溃的状态
2016-10-09T23:33:33.457348 + 00:00 heroku [web.1]:进程已退出
status 1
2016-10-09T23:33:35.414253 + 00:00 heroku [router]:at = error code = H10
desc =App crashedmethod = GET path =/host = farm-rooster.herokuapp.com
request_id = e88f1c0e-4ea5-4610-82d6-b437bf37ea0e fwd =186.203.235.191
dyno = connect = service = status = 503 bytes =
2016-10-09T23:33:36.117238 + 00:00 heroku [router]:at = error code = H10
desc =App crashedmethod = GET path =/ favicon.ico
host = farm-rooster.herokuapp.com
request_id = c8859482-b508-4e93-b9dc-3455558d13ed fwd = 186.203.235.191
dyno = connect = service = status = 503 bytes =您可以尝试添加 .com / articles / procfile#procfile-naming-and-locationrel =nofollow> Procfile 发送到Heroku之前。我认为它应该像web:npm run start
。
2 - 您不应该只发送dist文件夹到Heroku,你应该发送整个项目。 Heroku将建立它然后运行(这是Heroku的其中一个功能)。建议使用
3 - PM2,以便在应用程序中断时监视和重新启动。 Heroku会为你做,所以我不认为在这里使用PM2是非常有用的。
I have a clone of the repository https://github.com/ibnclaudius/express-mongoose-es6-rest-api, I want to deploy to Heroku. In the deployments instructions are written as follows:
# compile to ES5 1. npm run build or gulp # upload dist/ to your server 2. scp -rp dist/ user@dest:/path # install production dependencies only 3. npm i --production # Use any process manager to start your services 4. pm2 start dist/index.js
In production you need to make sure your server is always up so you should ideally use any of the process manager recommended here. We recommend pm2 as it has several useful features like it can be configured to auto-start your services if system is rebooted.
I'm not sure how to proceed. How can I deploy as recommended but in the context of Heroku? I tried to send through the Heroku CLI but did not succeed.
What I tried:
npm run build cd dist/ git init heroku git:remote -a farm-rooster git add . git commit -am "Início" git push heroku master
The application log:
2016-10-09T23:33:33.364424+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-10-09T23:33:33.364648+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-10-09T23:33:33.364968+00:00 app[web.1]: npm ERR! npm owner ls express-mongoose-es6-rest-api
2016-10-09T23:33:33.365079+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-10-09T23:33:33.368518+00:00 app[web.1]:
2016-10-09T23:33:33.368965+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-10-09T23:33:33.369132+00:00 app[web.1]: npm ERR!
/app/npm-debug.log2016-10-09T23:33:33.469487+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-09T23:33:33.457348+00:00 heroku[web.1]: Process exited with status 1
2016-10-09T23:33:35.414253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=farm-rooster.herokuapp.com request_id=e88f1c0e-4ea5-4610-82d6-b437bf37ea0e fwd="186.203.235.191" dyno= connect= service= status=503 bytes=
2016-10-09T23:33:36.117238+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=farm-rooster.herokuapp.com request_id=c8859482-b508-4e93-b9dc-3455558d13ed fwd="186.203.235.191" dyno= connect= service= status=503 bytes=
解决方案1 - You could try adding a Procfile to the project before sending it to Heroku. I think it should be like
web: npm run start
.2 - You shouldn't send just the dist folder to Heroku, you should send the whole project. Heroku will build it and then run (this is one of Heroku's features btw).
3 - PM2 is suggested so your application is monitored and restarted if it breaks. Heroku will do it for you so I don't think using PM2 here is really useful
这篇关于将nodejs应用程序部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!