我正在尝试将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);

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

最佳答案

您当前缺少一个npm启动脚本——heroku不知道如何运行您的应用程序。你有两个选择:
package.json文件中定义一个开始脚本,或者您可以创建一个Procfile来告诉heroku如何运行您的应用程序。
下面是一个例子:

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

关于node.js - MEAN app deplouy to heroku error,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31127101/

10-09 20:29
查看更多