简单的NodeJS部署到Heroku

Mar*_*ers 1 deployment heroku node.js

我正在尝试将一个非常简单的NodeJS应用程序部署到Heroku.

var http = require('http');
var server = http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('Hello World');
}).listen(3000);
Run Code Online (Sandbox Code Playgroud)

我已在本地测试它并运行以下命令.

heroku login
heroku create marktyers
git push heroku master
heroku ps:scale web=1
Run Code Online (Sandbox Code Playgroud)

该应用似乎部署,但当我查看URL时,我得到一个应用程序错误.

https://marktyers.herokuapp.com
Run Code Online (Sandbox Code Playgroud)

这是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=  
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 9

问题是使用固定端口号.如果我将端口设置process.env.PORT为app正确部署.

  • 把我加到那些把头撞到墙上的人名单上,直到他们读到这个答案为止:D (2认同)