我正在尝试将一个非常简单的NodeJS应用程序部署到Heroku。
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('Hello World');
}).listen(3000);
我已在本地测试并运行以下命令。
heroku login
heroku create marktyers
git push heroku master
heroku ps:scale web=1
该应用似乎已部署,但当我查看该网址时,我收到了应用错误。
https://marktyers.herokuapp.com
以下是heroku日志。
node server.js
heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=marktyers.heroku
app.com request_id=d2ccf200-f034-4b62-951a-0a1d3055bf35 fwd="90.244.82.220" dyno= connect= service= status=503 bytes=
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
heroku[web.1]: Stopping process with SIGKILL
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: Process exited with status 137
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=marktyers.herokuapp.com request_id=d63e046a-ec03-488b-930d-2ac05d006e56 fwd="90.244.82.220" dyno= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=marktyers.herokuapp.com request_id=21ba5a8b-2074-4798-8b40-ff0ea140bb1e fwd="90.244.82.220" dyno= connect= service= status=503 bytes=
Heroku提供的示例应用程序使用Express包,因此没有什么用来帮助我理解这个问题。
以下是推送时的消息:
remote: node_modules cached: false
remote:
remote: NPM_CONFIG_PRODUCTION=true
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: Resolving node version (latest stable) via semver.io...
remote: Downloading and installing node 0.12.2...
remote: Using default npm version: 2.7.4
remote:
remote: -----> Building dependencies
remote: No cache available
remote: Installing node modules
remote: npm WARN package.json Heroku@1.0.0 No README data
remote:
remote: -----> Checking startup method
remote: No Procfile; Adding 'web: npm start' to new Procfile
remote:
remote: -----> Finalizing build
remote: Creating runtime environment
remote: Exporting binary paths
remote: Cleaning npm artifacts
remote: Cleaning previous cache
remote: Caching results for future builds
remote:
remote: -----> Build succeeded!
remote:
remote: Heroku@1.0.0 /tmp/build_a046b18bb77857c1547f983f14ba04b9
remote: └── (empty)
remote:
remote: WARNING: Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 9.1MB
remote: -----> Launching... done, v3
remote: https://marktyers.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/marktyers.git
* [new branch] master -> master
答案 0 :(得分:9)
问题是使用固定端口号。如果我将端口设置为process.env.PORT
,则应用会正确部署。