我有一个super simple express/node application来测试如何使用Heroku。这是我的整个app.js
文件:
const express = require('express')
const app = express()
const port = '8080' || process.env.PORT;
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(port, function () {
console.log(`Server started on port ${port}`)
})
它编译得很完美,但是当我尝试向网站发送请求时,我收到了一个应用程序错误:
我在项目文件夹中运行git push heroku master
。
这是回复:
一切似乎都在发挥作用。在我的Procfile
我有
web: npm start
在我的package.json
我有脚本
"start": "node app.js"
当我尝试连接时
我收到上面的错误。我运行heroku logs
并获得此输出:
λ heroku logs
2018-05-07T10:59:05.711233+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
2018-05-07T10:59:05.711235+00:00 app[web.1]: at startup (internal/bootstrap/node.js:228:19)
2018-05-07T10:59:05.720402+00:00 app[web.1]: npm ERR! Failed at the html_css-ma1@1.0.0 start script.
2018-05-07T10:59:05.720552+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-05-07T10:59:05.807864+00:00 app[web.1]:
2018-05-07T10:59:05.808109+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-05-07T10:59:05.808259+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-05-07T10_59_05_722Z-debug.log
2018-05-07T10:59:05.880130+00:00 heroku[web.1]: Process exited with status 1
2018-05-07T10:59:05.902499+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-07T10:59:05.905620+00:00 heroku[web.1]: State changed from crashed to starting
2018-05-07T10:59:08.281431+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-07T10:59:10.714118+00:00 app[web.1]: npm WARN npm npm does not support Node.js v10.0.0
2018-05-07T10:59:10.714580+00:00 app[web.1]: npm WARN npm You should probably upgrade to a newer version of node as we
2018-05-07T10:59:10.714828+00:00 app[web.1]: npm WARN npm can't make any promises that npm will work with this version.
2018-05-07T10:59:10.715125+00:00 app[web.1]: npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
2018-05-07T10:59:10.715364+00:00 app[web.1]: npm WARN npm You can find the latest version at https://nodejs.org/
2018-05-07T10:59:10.806649+00:00 app[web.1]:
2018-05-07T10:59:10.806654+00:00 app[web.1]: > node app.js
2018-05-07T10:59:10.806652+00:00 app[web.1]: > html_css-ma1@1.0.0 start /app
2018-05-07T10:59:10.806656+00:00 app[web.1]:
2018-05-07T10:59:11.229162+00:00 app[web.1]: events.js:167
2018-05-07T10:59:11.229201+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-05-07T10:59:11.229203+00:00 app[web.1]: ^
2018-05-07T10:59:11.229205+00:00 app[web.1]:
2018-05-07T10:59:11.229207+00:00 app[web.1]: Error: listen EACCES 0.0.0.0:80
2018-05-07T10:59:11.229209+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:19)
2018-05-07T10:59:11.229212+00:00 app[web.1]: at Server.listen (net.js:1466:7)
2018-05-07T10:59:11.229210+00:00 app[web.1]: at listenInCluster (net.js:1378:12)
2018-05-07T10:59:11.229214+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-05-07T10:59:11.229215+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:10:5)
2018-05-07T10:59:11.229217+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:678:30)
2018-05-07T10:59:11.229218+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
2018-05-07T10:59:11.229220+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:589:32)
2018-05-07T10:59:11.229222+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
2018-05-07T10:59:11.229224+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:520:3)
2018-05-07T10:59:11.229225+00:00 app[web.1]: Emitted 'error' event at:
2018-05-07T10:59:11.229227+00:00 app[web.1]: at emitErrorNT (net.js:1357:8)
2018-05-07T10:59:11.229228+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:174:19)
2018-05-07T10:59:11.229230+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
2018-05-07T10:59:11.229232+00:00 app[web.1]: at startup (internal/bootstrap/node.js:228:19)
2018-05-07T10:59:11.229233+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)
2018-05-07T10:59:11.237647+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-05-07T10:59:11.238047+00:00 app[web.1]: npm ERR! errno 1
2018-05-07T10:59:11.239658+00:00 app[web.1]: npm ERR! html_css-ma1@1.0.0 start: `node app.js`
2018-05-07T10:59:11.239812+00:00 app[web.1]: npm ERR! Exit status 1
2018-05-07T10:59:11.240137+00:00 app[web.1]: npm ERR!
2018-05-07T10:59:11.240341+00:00 app[web.1]: npm ERR! Failed at the html_css-ma1@1.0.0 start script.
2018-05-07T10:59:11.240579+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-05-07T10:59:11.250911+00:00 app[web.1]:
2018-05-07T10:59:11.251110+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-05-07T10:59:11.251244+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-05-07T10_59_11_242Z-debug.log
2018-05-07T10:59:11.306925+00:00 heroku[web.1]: Process exited with status 1
2018-05-07T10:59:11.321717+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-07T11:04:53.029487+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stormy-garden-84636.herokuapp.com request_id=32bd2f98-0cec-4f5d-8755-94164154d506 fwd="109.247.251.198" dyno= connect= service= status=503 bytes= protocol=https
2018-05-07T11:04:53.667123+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=stormy-garden-84636.herokuapp.com request_id=7864ed19-2cee-40d9-9c60-825963ddc827 fwd="109.247.251.198" dyno= connect= service= status=503 bytes= protocol=https
2018-05-07T11:49:12.389964+00:00 heroku[web.1]: State changed from crashed to starting
2018-05-07T11:49:15.663542+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-07T11:49:18.056472+00:00 app[web.1]: npm WARN npm npm does not support Node.js v10.0.0
2018-05-07T11:49:18.057100+00:00 app[web.1]: npm WARN npm You should probably upgrade to a newer version of node as we
2018-05-07T11:49:18.057382+00:00 app[web.1]: npm WARN npm can't make any promises that npm will work with this version.
2018-05-07T11:49:18.057751+00:00 app[web.1]: npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
2018-05-07T11:49:18.058023+00:00 app[web.1]: npm WARN npm You can find the latest version at https://nodejs.org/
2018-05-07T11:49:18.165241+00:00 app[web.1]:
2018-05-07T11:49:18.165244+00:00 app[web.1]: > html_css-ma1@1.0.0 start /app
2018-05-07T11:49:18.165246+00:00 app[web.1]: > node app.js
2018-05-07T11:49:18.165247+00:00 app[web.1]:
2018-05-07T11:49:18.538620+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:10:5)
2018-05-07T11:49:18.538622+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:678:30)
2018-05-07T11:49:18.538623+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
2018-05-07T11:49:18.538625+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:589:32)
2018-05-07T11:49:18.538626+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
2018-05-07T11:49:18.538628+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:520:3)
2018-05-07T11:49:18.538629+00:00 app[web.1]: Emitted 'error' event at:
2018-05-07T11:49:18.538631+00:00 app[web.1]: at emitErrorNT (net.js:1357:8)
2018-05-07T11:49:18.538632+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:174:19)
2018-05-07T11:49:18.538634+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
2018-05-07T11:49:18.538635+00:00 app[web.1]: at startup (internal/bootstrap/node.js:228:19)
2018-05-07T11:49:18.538637+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)
2018-05-07T11:49:18.547708+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-05-07T11:49:18.538619+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-05-07T11:49:18.538609+00:00 app[web.1]:
2018-05-07T11:49:18.538611+00:00 app[web.1]: Error: listen EACCES 0.0.0.0:80
2018-05-07T11:49:18.538615+00:00 app[web.1]: at listenInCluster (net.js:1378:12)
2018-05-07T11:49:18.538616+00:00 app[web.1]: at Server.listen (net.js:1466:7)
2018-05-07T11:49:18.547712+00:00 app[web.1]: npm ERR! errno 1
2018-05-07T11:49:18.551362+00:00 app[web.1]: npm ERR! html_css-ma1@1.0.0 start: `node app.js`
2018-05-07T11:49:18.538583+00:00 app[web.1]: events.js:167
2018-05-07T11:49:18.551365+00:00 app[web.1]: npm ERR! Exit status 1
2018-05-07T11:49:18.551367+00:00 app[web.1]: npm ERR!
2018-05-07T11:49:18.538605+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-05-07T11:49:18.538607+00:00 app[web.1]: ^
2018-05-07T11:49:18.538613+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:19)
2018-05-07T11:49:18.577541+00:00 app[web.1]:
2018-05-07T11:49:18.551369+00:00 app[web.1]: npm ERR! Failed at the html_css-ma1@1.0.0 start script.
2018-05-07T11:49:18.551374+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-05-07T11:49:18.578108+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-05-07T11_49_18_551Z-debug.log
2018-05-07T11:49:18.577866+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-05-07T11:49:18.674693+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-07T11:49:18.658509+00:00 heroku[web.1]: Process exited with status 1
2018-05-07T12:04:35.580986+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stormy-garden-84636.herokuapp.com request_id=667ed5c8-b4df-44b9-8eb8-eaac78fb0b95 fwd="109.247.251.198" dyno= connect= service= status=503 bytes= protocol=https
我不确定该怎么做。有谁知道我做错了什么?
答案 0 :(得分:0)
您正在向后定义port
变量:
const port = '8080' || process.env.PORT;
由于文字'8080'
是真实的,port
将始终被指定为'8080'
。
||
的短路行为是它使用它从左到右找到的第一个真值:
短路评估
当逻辑表达式从左到右进行评估时,它们会被测试可能的短路&#34;评估使用以下规则:
false && (anything)
短路评估为假。true || (anything)
短路评估为真。
使用
const port = process.env.PORT || '8080';
代替。