10

基本的なnode.jsアプリケーションを作成し、問題なくHerokuにデプロイできました。package.jsonProcfileを作成しましたが、ログから、実行中のプロセスがないため、応答を取得できないことがわかります。何が問題なのですか?

PS:Expressフレームワークを使いたくない

私のコード:

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();

  console.log("I am working");
}).listen(8888);

私のpackage.json:

{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
  },
  "engines": {
    "node": "0.8.x",
    "npm": "1.1.x"
  }
}

ログ:

2012-10-22T12:36:58+00:00 heroku[slugc]: Slug compilation started
2012-10-22T12:37:07+00:00 heroku[slugc]: Slug compilation finished
2012-10-22T12:40:55+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
2012-10-22T12:50:44+00:00 heroku[router]: Error H14 (No web processes running) -> GET aqueous-bastion-6914.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
4

4 に答える 4

37

herokuアプリをスケーリングしましたか?

$ heroku ps:scale web=1

これは必須の手順です。これ1は、アプリに生成するプロセスの数です。

于 2012-10-22T13:42:09.717 に答える
26

ポートを変更する

から

.listen(8888)

.listen(process.env.PORT || 8888)
于 2012-10-22T14:07:45.830 に答える
3

Procfileの内容は何ですか?アプリ名と一致しますか?

$ ls
app.js Procfile
$ cat Procfile
web: node app$
$
于 2012-10-22T14:15:28.757 に答える
2

私がしなければならなかったこと(Expressをスケーリングしたり使用したりする必要はありませんでした)。

  1. ルートディレクトリにProcfileを作成します(文字通りProcfileと呼ばれるファイルで、拡張子はありません)。
    Procfile内に、次のように入力します。

    web: node server.js
    
  2. スクリプトとエンジンをpackage.jsonに追加します

    "scripts": {
            "start": "node server.js"
    }
    
    "engines": {
            "node": "8.9.3"
    }
    
  3. server.jsのポートを更新します

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

なぜ..

  1. アプリを起動するために実行するコマンドを明示的に宣言します。Herokuは、プロセスタイプを指定するProcfileを探します

  2. スクリプトの場合、ビルドプロセス中にルートディレクトリにProcfileが存在しない場合、npmstartを実行してWebプロセスを開始します。エンジンの場合、開発しているランタイムに一致し、Herokuで使用するノードバージョンを指定します。

  3. Herokuはすでにアプリにポートを割り当てて環境に追加しているため、ポートを固定数に設定することはできません。

資力:

https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

https://devcenter.heroku.com/articles/troubleshooting-node-deploys

https://devcenter.heroku.com/articles/deploying-nodejs

于 2018-05-17T07:54:40.250 に答える