我已将我的第一个Node应用程序部署到Heroku。它与foreman start
运行良好,但在Heroku上崩溃。
proc文件存在且有效:foreman check
valid procfile detected (web)
内容web: node app.js
根据heroku logs
,Express-cors模块存在问题。
2015-05-25T09:29:32.530535+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-05-25T09:29:33.912050+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-05-25T09:29:33.912079+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-05-25T09:29:34.264204+00:00 app[web.1]: module.js:338
2015-05-25T09:29:34.264210+00:00 app[web.1]: throw err;
2015-05-25T09:29:34.264212+00:00 app[web.1]: ^
2015-05-25T09:29:34.264214+00:00 app[web.1]: Error: Cannot find module 'express-cors'
2015-05-25T09:29:34.264216+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:336:15)
2015-05-25T09:29:34.264217+00:00 app[web.1]: at Function.Module._load (module.js:278:25)
2015-05-25T09:29:34.264218+00:00 app[web.1]: at Module.require (module.js:365:17)
2015-05-25T09:29:34.264220+00:00 app[web.1]: at require (module.js:384:17)
2015-05-25T09:29:34.264222+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:2:12)
2015-05-25T09:29:34.264223+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-05-25T09:29:34.264224+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-05-25T09:29:34.264226+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-05-25T09:29:34.264228+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-05-25T09:29:34.264229+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-05-25T09:29:35.085157+00:00 heroku[web.1]: State changed from starting to crashed
2015-05-25T09:29:35.086239+00:00 heroku[web.1]: State changed from crashed to starting
2015-05-25T09:29:35.069352+00:00 heroku[web.1]: Process exited with status 1
2015-05-25T09:29:37.209488+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-05-25T09:29:38.965715+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-05-25T09:29:38.965737+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-05-25T09:29:39.288408+00:00 app[web.1]: module.js:338
2015-05-25T09:29:39.288412+00:00 app[web.1]: throw err;
2015-05-25T09:29:39.288416+00:00 app[web.1]: ^
2015-05-25T09:29:39.288418+00:00 app[web.1]: Error: Cannot find module 'express-cors'
2015-05-25T09:29:39.288421+00:00 app[web.1]: at Function.Module._load (module.js:278:25)
2015-05-25T09:29:39.288420+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:336:15)
2015-05-25T09:29:39.288422+00:00 app[web.1]: at Module.require (module.js:365:17)
2015-05-25T09:29:39.288425+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:2:12)
2015-05-25T09:29:39.288424+00:00 app[web.1]: at require (module.js:384:17)
2015-05-25T09:29:39.288426+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-05-25T09:29:39.288428+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-05-25T09:29:39.288429+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-05-25T09:29:39.288432+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-05-25T09:29:39.288431+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-05-25T09:29:39.982048+00:00 heroku[web.1]: State changed from starting to crashed
2015-05-25T09:29:39.971753+00:00 heroku[web.1]: Process exited with status 1
2015-05-25T09:29:41.341772+00:00 heroku[api]: Scale to web=1 by email@gmail.com
2015-05-25T09:29:48.007388+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-spire-2945.herokuapp.com request_id=576a02a2-447d-48aa-ab21-63aa576027c1 fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
2015-05-25T09:29:49.472658+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=immense-spire-2945.herokuapp.com request_id=c18744e7-f029-4035-a0ef-cdf6b0d25305 fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
2015-05-25T09:29:52.332338+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-spire-2945.herokuapp.com request_id=8f5750d3-bb54-43d2-a86d-c1176af43277 fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
2015-05-25T09:29:56.998627+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-spire-2945.herokuapp.com request_id=296fa816-f2f3-458f-8c85-95bc7a53057b fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
2015-05-25T09:33:19.006725+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-spire-2945.herokuapp.com request_id=f99e20dd-f73a-4ccd-b746-0bd8ec021d27 fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
2015-05-25T09:33:21.467535+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-spire-2945.herokuapp.com request_id=2937160d-6635-4d73-8d25-a3ee0c73e472 fwd="213.113.58.143" dyno= connect= service= status=503 bytes=
我该如何解决这个问题?
编辑:Heroku支持非常有帮助。 如果您遇到此问题,首先应检查package.json文件是否包含所有必需的依赖项。
其次,您应该将以下内容添加到app.js文件中:
app.set('port', (process.env.PORT || 5000));
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
否则,该应用将尝试http://127.0.0.1:3000/
。