【问题标题】:MEAN app deplouy to heroku error平均应用程序部署到heroku错误
【发布时间】:2015-09-16 14:10:23
【问题描述】:

我正在尝试将 node.js 应用程序部署到 heroku。

一切似乎都很顺利,直到我尝试通过 heroku 在应用程序中打开

heroku open

然后我得到

Opening nameless-taiga-6317... done

但我的浏览器出现应用程序错误,heroku 日志将其吐出:

←[36m2015-06-29T20:56:25.562616+00:00 heroku[web.1]:←[0m Process exited with status 1
←[36m2015-06-29T20:56:27.685099+00:00 heroku[web.1]:←[0m Starting process with command `npm start`
←[36m2015-06-29T20:56:29.513842+00:00 app[web.1]:←[0m Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
←[36m2015-06-29T20:56:29.513866+00:00 app[web.1]:←[0m Recommending WEB_CONCURRENCY=1
←[36m2015-06-29T20:56:30.256436+00:00 app[web.1]:←[0m npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
←[36m2015-06-29T20:56:30.257127+00:00 app[web.1]:←[0m npm ERR! npm  v2.11.2
←[36m2015-06-29T20:56:30.255876+00:00 app[web.1]:←[0m npm ERR! Linux 3.13.0-49-generic
←[36m2015-06-29T20:56:30.256743+00:00 app[web.1]:←[0m npm ERR! node v0.12.5
←[36m2015-06-29T20:56:30.257367+00:00 app[web.1]:←[0m
←[36m2015-06-29T20:56:30.257575+00:00 app[web.1]:←[0m npm ERR! missing script: start
←[36m2015-06-29T20:56:30.257725+00:00 app[web.1]:←[0m npm ERR!
←[36m2015-06-29T20:56:30.257836+00:00 app[web.1]:←[0m npm ERR! If you need help, you may report this error at:
←[36m2015-06-29T20:56:30.257951+00:00 app[web.1]:←[0m npm ERR!     <https://github.com/npm/npm/issues>
←[36m2015-06-29T20:56:30.263537+00:00 app[web.1]:←[0m
←[36m2015-06-29T20:56:30.263763+00:00 app[web.1]:←[0m npm ERR! Please include the following file with any support request:
←[36m2015-06-29T20:56:30.264024+00:00 app[web.1]:←[0m npm ERR!     /app/npm-debug.log
←[36m2015-06-29T20:56:31.030724+00:00 heroku[web.1]:←[0m Process exited with status 1
←[36m2015-06-29T20:56:31.048838+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[33m2015-06-29T21:01:55.665028+00:00 heroku[api]:←[0m Scale to web=1 by david.shave@gmail.com
←[32m2015-06-29T21:02:35.497433+00:00 heroku[router]:←[0m at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-taiga-6317.herokuapp.com 
...

这是我的一些 server.js 文件

var mongoose = require('mongoose');

....

//connect database

if (env === 'development') {
mongoose.connect('mongodb://localhost/multivision');
} else {

mongoose.connect('mongodb://amp3rsand:multivision@ds039550.mongolab.com:39550/multivision');
}

....

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error...'));
db.once('open', function callback() {
    console.log('multivision db opened');
});

...

var port = process.env.PORT || 3030;
app.listen(port);

我正在浏览一个教程,但没有从作者那里得到任何帮助,所以希望这里有人能指出我正确的方向。

谢谢。

【问题讨论】:

    标签: node.js mongodb heroku


    【解决方案1】:

    您目前缺少一个 npm 启动脚本——Heroku 不知道如何运行您的应用程序。你有两个选择:

    在您的 package.json 文件中定义一个启动脚本,或者您可以创建一个 Procfile 告诉 Heroku 如何运行您的应用程序。

    这是一个例子:

    # Procfile
    web: node index.js # Tell Heroku what command to use to run your app.
    

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 2017-04-18
      • 2018-05-09
      • 2018-08-18
      • 2020-08-08
      • 2020-07-22
      • 1970-01-01
      • 2016-09-10
      • 2017-02-09
      相关资源
      最近更新 更多