简体   繁体   English

将Node.js应用程序部署到Heroku

[英]Deploy nodejs application to Heroku

I have a clone of the repository https://github.com/ibnclaudius/express-mongoose-es6-rest-api , I want to deploy to Heroku. 我有一个存储库的克隆https://github.com/ibnclaudius/express-mongoose-es6-rest-api ,我想部署到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. 我们建议pm2,因为它具有一些有用的功能,例如可以将其配置为在重新引导系统时自动启动服务。

I'm not sure how to proceed. 我不确定如何进行。 How can I deploy as recommended but in the context of Heroku? 如何在Heroku的背景下按照建议进行部署? I tried to send through the Heroku CLI but did not succeed. 我试图通过Heroku CLI发送,但没有成功。

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! 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! 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! 2016-10-09T23:33:33.364968 + 00:00 app [web.1]:npm ERR! npm owner ls express-mongoose-es6-rest-api 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.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.368518 + 00:00 app [web.1]:

2016-10-09T23:33:33.368965+00:00 app[web.1]: npm ERR! 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! 2016-10-09T23:33:33.369132 + 00:00 app [web.1]:npm ERR!
/app/npm-debug.log /app/npm-debug.log

2016-10-09T23:33:33.469487+00:00 heroku[web.1]: State changed from starting to crashed 2016-10-09T23:33:33.469487 + 00:00 heroku [web.1]:状态从开始更改为崩溃

2016-10-09T23:33:33.457348+00:00 heroku[web.1]: Process exited with status 1 2016-10-09T23:33:33.457348 + 00:00 heroku [web.1]:进程退出,状态为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:35.414253 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ /”主机= farm-rooster.herokuapp.com request_id = e88f1c0e -4ea5-4610-82d6-b437bf37ea0e fwd =“ 186.203.235.191” dyno = connect = service = status = 503字节=

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= 2016-10-09T23:33:36.117238 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ / favicon.ico”主机= farm-rooster.herokuapp.com request_id = c8859482-b508-4e93-b9dc-3455558d13ed fwd =“ 186.203.235.191” dyno = connect = service =状态= 503字节=

1 - You could try adding a Procfile to the project before sending it to Heroku. 1-您可以先将Procfile添加到项目中,然后再将其发送到Heroku。 I think it should be like web: npm run start . 我认为它应该像web: npm run start

2 - You shouldn't send just the dist folder to Heroku, you should send the whole project. 2-您不应该只将dist文件夹发送到Heroku,而应该发送整个项目。 Heroku will build it and then run (this is one of Heroku's features btw). Heroku将构建它然后运行(这是Heroku的功能之一)。

3 - PM2 is suggested so your application is monitored and restarted if it breaks. 3-建议使用PM2,以便监视您的应用程序并在其中断时重新启动。 Heroku will do it for you so I don't think using PM2 here is really useful Heroku会为您做到这一点,所以我认为在这里使用PM2并不是真的有用

Just to make it clear regarding Procfile and handling /dist folder 只是为了清楚地说明Procfile和处理/dist文件夹

Procfile, Procfile,

To determine how to start your app, Heroku first looks for a Procfile. 为了确定如何启动您的应用,Heroku首先寻找一个Procfile。 If no Procfile exists for a Node.js app, we will attempt to start a default web process via the start script in your package.json. 如果Node.js应用程序不存在Procfile,我们将尝试通过package.json中的启动脚本启动默认的Web进程。 So you can either have Procfile or you can define Start section in your package.json. 因此,您可以拥有Procfile,也可以在package.json中定义“开始”部分。 eg "start": "node server.js" 例如"start": "node server.js"

/dist folder /dist文件夹

You have two options 你有两个选择

  1. Push dist folder to heroku along with other application stuff. dist文件夹与其他应用程序一起推送到heroku。
  2. Don't push dist and keep it ignored in your gitignore file. 不要推送dist并将其保留在gitignore文件中。 Use postintall script in your package.json to create /dist folder "postinstall": "ng build --prod" postinstall script 在package.json中使用postintall script创建/ dist文件夹"postinstall": "ng build --prod" 后安装脚本

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

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