Heroku node.js应用程序崩溃

时间:2016-10-25 04:21:03

标签: node.js heroku

我尝试通过Heroku部署node.js. 但是有应用程序错误。

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 322 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: 
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote: 
remote: -----> Installing binaries
remote:        engines.node (package.json):  v6.8.1
remote:        engines.npm (package.json):   3.10.8
remote:        
remote:        Resolving node version v6.8.1 via semver.io...
remote:        Downloading and installing node 6.8.1...
remote:        npm 3.10.8 already installed with node
remote: 
remote: -----> Restoring cache
remote:        Loading 2 from cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (not cached - skipping)
remote: 
remote: -----> Building dependencies
remote:        Installing node modules (package.json)
remote: 
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (nothing to cache)
remote: 
remote: -----> Build succeeded!
remote:        ├── cookie@0.3.1
remote:        ├── ejs@2.5.2
remote:        └── jade@1.11.0
remote:        
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 14.5M
remote: -----> Launching...
remote:        Released v9
remote:        https://sawartc.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/sawartc.git
   7d9216c..973d8ba  master -> master
sawamuratakashikan-no-MacBook-Pro:node sawamuratakahiro$ heroku open

此部署可能会成功。

但它发生了应用程序错误。

然后,这是heroku日志。

2016-10-24T15:25:07.521109+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-24T15:25:07.500572+00:00 heroku[web.1]: Process exited with status 137
2016-10-24T17:10:24.410630+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-24T17:10:26.487227+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-24T17:10:29.973959+00:00 app[web.1]: 
2016-10-24T17:10:29.973971+00:00 app[web.1]: > node@1.0.0 start /app
2016-10-24T17:10:29.973972+00:00 app[web.1]: > node sampleapp.js
2016-10-24T17:10:29.973973+00:00 app[web.1]: 
2016-10-24T17:10:30.163591+00:00 app[web.1]: Server running at http://127.0.0.1:1337/
2016-10-24T17:11:26.793014+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2016-10-24T17:11:26.755681+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-24T17:11:26.755825+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-24T17:11:26.903907+00:00 heroku[web.1]: Process exited with status 22
2016-10-24T17:11:26.919339+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-24T20:08:20.748447+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-24T20:08:22.155076+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-24T20:08:24.669537+00:00 app[web.1]: > node@1.0.0 start /app
2016-10-24T20:08:24.669514+00:00 app[web.1]: 
2016-10-24T20:08:24.669538+00:00 app[web.1]: > node sampleapp.js
2016-10-24T20:08:24.669539+00:00 app[web.1]: 
2016-10-24T20:08:24.786219+00:00 app[web.1]: Server running at http://127.0.0.1:1337/
2016-10-24T20:09:22.309836+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-24T20:09:22.309836+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-24T20:09:22.399015+00:00 heroku[web.1]: Process exited with status 137
2016-10-24T20:09:22.406141+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T01:40:39.946449+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-25T01:40:41.519699+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-25T01:40:43.843569+00:00 app[web.1]: 
2016-10-25T01:40:43.843581+00:00 app[web.1]: > node@1.0.0 start /app
2016-10-25T01:40:43.843581+00:00 app[web.1]: > node sampleapp.js
2016-10-25T01:40:43.843582+00:00 app[web.1]: 
2016-10-25T01:40:43.943591+00:00 app[web.1]: Server running at http://127.0.0.1:1337/
2016-10-25T01:41:42.057140+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-25T01:41:42.057234+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-25T01:41:42.172614+00:00 heroku[web.1]: Process exited with status 137
2016-10-25T01:41:42.207278+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T03:42:53.015078+00:00 heroku[api]: Deploy 2e44739 by 
2016-10-25T03:42:53.015138+00:00 heroku[api]: Release v7 created by 
2016-10-25T03:42:53.546204+00:00 heroku[slug-compiler]: Slug compilation finished
2016-10-25T03:42:53.546194+00:00 heroku[slug-compiler]: Slug compilation started
2016-10-25T03:42:53.630591+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-25T03:42:54.901534+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-25T03:42:57.073592+00:00 app[web.1]: 
2016-10-25T03:42:57.073608+00:00 app[web.1]: > node@1.0.0 start /app
2016-10-25T03:42:57.073608+00:00 app[web.1]: > node sampleapp.js
2016-10-25T03:42:57.192757+00:00 app[web.1]: Server running at http://127.0.0.1:1337/
2016-10-25T03:42:57.073609+00:00 app[web.1]: 
2016-10-25T03:43:55.242924+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-25T03:43:55.242924+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-25T03:43:55.403793+00:00 heroku[web.1]: Process exited with status 137
2016-10-25T03:43:55.418227+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T03:43:55.419140+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-25T03:43:56.641767+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-25T03:43:58.885658+00:00 app[web.1]: > node@1.0.0 start /app
2016-10-25T03:43:58.885646+00:00 app[web.1]: 
2016-10-25T03:43:58.885659+00:00 app[web.1]: > node sampleapp.js
2016-10-25T03:43:58.885663+00:00 app[web.1]: 
2016-10-25T03:43:58.988687+00:00 app[web.1]: Server running at http://127.0.0.1:1337/
2016-10-25T03:44:20.981992+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=sawartc.herokuapp.com request_id=19ae4ca5-679f-4ef1-9e5c-9408dd6963b2 fwd="219.117.193.211" dyno= connect= service= status=503 bytes=
2016-10-25T03:44:57.129700+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-25T03:44:57.129700+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-25T03:44:57.244921+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T03:44:57.267311+00:00 heroku[web.1]: Process exited with status 137

那么,我该怎么做才能部署这个node.js app。

2 个答案:

答案 0 :(得分:5)

从日志中看,您似乎绑定到动态端口1337,但是它在本地运行,Heroku允许您仅使用端口8080。定义端口的最佳方法是:

var port = process.env.PORT || 1337;

所以Heroku使用它的端口,在本地运行代码时,你仍然可以使用1337端口。

答案 1 :(得分:0)

在package.json文件中需要一个启动脚本。像这样:

"scripts": {
    "start": "node server.js"
}