2016-04-01 40 views
1

CRUD NodeアプリケーションをHerokuに配備しようとしましたが、送信できません。インデックスページを開始することさえできます。私は、APIを扱い、インデックスページを提供したいが、なんらかの理由でそれを行うことができないアプリケーションのすべてをコメントアウトしました。Heroku Node.jsエラーheroku [router]:at =エラーコード= H10 desc = "App crashed"メソッド= GETパス= "/"

現在、私は可能な限りEJSのようなレンダリングエンジンを使用していません。

ディレクトリ構造:

/invoicr (root) 
    package.json 
    Procfile 
    server.js 
    /client 
    index.html 

package.json

{ 
    "name": "invoicr", 
    "version": "1.0.0", 
    "description": "", 
    "main": "server.js", 
    "scripts": { 
    "start": "node server.js", 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "body-parser": "^1.15.0", 
    "express": "^4.13.4", 
    "mongoose": "^4.4.7" 
    } 
} 

Procfile(私はpackage.jsonとしてこれを必要とするかどうかわからないスクリプトは、コマンドを起動しました)

web: node server.js 
私は var server = ...ていることにコメントアウトするとすぐに

var server = http.createServer(function(req, res){ 
    res.writeHead(200, {'Content-Type':'text/html'}); 
    res.end('<h1>World</h1>'); 
}); 
server.listen(port); 

しかし、HTMLファイルを提供しよう:

server.js

var port = Number(process.env.PORT || 3000); 
var express = require('express'); 
var app = express(); 

app.use(express.static(__dirname + '/client'));  
app.get('/', function(req, res){ 
    res.sendFile('/index.html'); //I've tried playing around with the path multiple ways and still get errors 
}); 

app.listen(port); 

私はで動作するように簡単な応答を取得することができました次のエラーが表示されます。 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=invoicr-test-app.herokuapp.com

展開コマンド

  • git add .
  • git commit -m "message"
  • git push heroku master
  • heroku ps:scale web=1
  • heroku open

私が欠けているか、正しくやっていないよ何上の任意のヘルプは大、おかげでいただければ幸いです。

編集だからいつものように、それは単純なものだ、私は彼らがpackage.jsonでDEVとして設定されていたので、私の依存関係がインストールされていないように見えます。この問題のトラブルシューティングを手伝ってくださった皆様、ありがとうございます。デフォルトのHerokuのことで

package.json

{ 
    "name": "invoicr", 
    "version": "1.0.0", 
    "description": "", 
    "main": "server.js", 
    "scripts": { 
    "start": "node server.js", 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "body-parser": "^1.15.0", 
    "express": "^4.13.4", 
    "mongoose": "^4.4.7" 
    } 
} 
+0

あなたは 'の解像度を試してみました。sendFile(__ dirname + '/index.html'); '? – rgvassar

+0

'res.sendFile( 'index.html'、{root:path.join(__ dirname、 'client /')});' –

+0

これで、ExpressがHerokuにインストールされないような、 'エラー:Cannon find module 'express'' –

答えて

0

あなたはHerokuのからdependencies

として設定する必要がありますdevDependenciesでDEPSをインストールしていない:

Npm reads configuration from any environment variables beginning with NPM_CONFIG. We set production=true by default to install dependencies only. If you would like to install additional devDependencies, you can disable this behavior: heroku config:set NPM_CONFIG_PRODUCTION=false

+0

私は他のソースコードを見て、devDepenenciesを認識し、開発者を落とし、文字通り、展開することができたことを発見しました:)。 –

関連する問題