我正在尝试在他们的网站上新创建的 Heroku 应用程序上运行 Node 应用程序。我按照他们的步骤操作,但在显示应用程序状态时仍然遇到错误。
我跟着Node.js 入门 https://devcenter.heroku.com/articles/getting-started-with-nodejs部分没有heroku create
命令,因为我已经从网络创建了。
所以当我跑步时:heroku ps:scale web=1
它向我展示:
扩展测功机...完成,现在以 1:Free 运行网络
但跑步时heroku ps
:
=== web(免费):npm run start (1)
web.1: 崩溃 2018/10/25 11:25:49 -0300 (~ 8m 前)
所以我的登录heroku logs --tail
告诉我这个错误:
2018-10-25T14:25:44.000000+00:00 app[api]: 构建成功
2018-10-25T14:25:46.451739+00:00 heroku[web.1]:使用命令启动进程npm run start
2018-10-25T14:25:49.113832+00:00 应用程序[web.1]:
2018-10-25T14:25:49.113864+00:00 应用程序[web.1]: >[电子邮件受保护] /cdn-cgi/l/email-protection启动/应用程序
2018-10-25T14:25:49.113866 + 00:00应用程序[web.1]:>节点server.js
2018-10-25T14:25:49.113867+00:00 应用程序[web.1]:
2018-10-25T14:25:49.418151+00:00 应用程序[web.1]: events.js:167
2018-10-25T14:25:49.418191+00:00 app[web.1]: 抛出错误; // 未处理的“错误”事件
2018-10-25T14:25:49.418193+00:00 应用程序[web.1]: ^
2018-10-25T14:25:49.418194+00:00 应用程序[web.1]:
2018-10-25T14:25:49.418196 + 00:00应用程序[web.1]:错误:听EACCES 0.0.0.0:80
所以我检查了一下我在设置时是否犯了错误。
我使用简单的 Express 路由和服务器以及以下代码:
app.get('/', (req, res) => { ... });
app.listen(80, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
我还确保我添加了engines
to 包.json:
"scripts": {
"start": "node server.js"
},
"engines": {
"node": "10.11.0",
"npm": "6.4.1"
},
我还创建了一个Procfile根路径中的文件web: npm run start
inside.
因此,当检查完所有内容后,我只需运行这些命令,一切看起来都很棒,直到我检查日志或访问应用程序:
git commit -am "my commit text"
git push heroku master
我在日志中看到这一点:
远程:-----> 正在压缩...
远程:完成:18.3M
远程:-----> 正在启动...
远程:发布 v12
偏僻的:https://my-app.herokuapp.com/ https://my-app.herokuapp.com/部署到 Heroku
remote:
远程:正在验证部署...已完成。
To https://git.heroku.com/my-app.git https://git.heroku.com/my-app.git
3656da0..f1eb078 主站 -> 主站
那么...关于我做错了什么有什么建议吗?提前致谢。