我一直在寻找解决方案,但我尝试的任何事情都会产生相同的结果。我认为它必须与localhost有关,但我不知道出了什么问题。这些是我运行heroku日志时遇到的错误。
2013-08-05T07:10:34.804131+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.424107+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.927263+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:20:26.552533+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
我的server.js文件看起来像这样。
//create an app server
var express = require('express')
, flash = require('connect-flash')
, helpers = require('view-helpers')
, mongoStore = require('connect-mongo')(express)
, fs = require('fs')
, mongoose = require('mongoose')
, passport=require('passport')
//create/connect to database
var dbname = 'test';
var uri = 'mongodb://localhost/' + dbname;
mongoose.connect(uri);
console.log('server.js : connecting to %s', uri);
//express settings
var app = express()
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser('keyboard cat' ));
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(express.session({
secret: 'spoc',
store: new mongoStore({
url: 'mongodb://localhost/' + dbname,
collection : 'sessions'
})
}))
app.use(passport.initialize());
app.use(passport.session());
app.use(flash())
app.use(helpers('node-beginners'))
app.use(app.router);
});
//start app
var PORT = process.env.PORT || 3000
app.listen(PORT)
console.log('Express app started on port '+PORT)
//expose app
exports = module.exports = app
我已经尝试了几乎我在其他帖子中找到的所有内容,但我仍然遇到此错误。请帮忙!
答案 0 :(得分:3)
我认为您的错误与mongodb实例有关。要在Heroku中开始使用mongodb,请查看他们的documentation。
要获取正确的连接URI,请检查here
答案 1 :(得分:0)
我得到了同样的错误 app_dir [必填]应用程序目录 -c [可选]集群,值[可选]
-d [可选] daemonize进程永远使用
-p [可选]端口,值[必需]
[nodemon] app崩溃 - 在开始之前等待文件更改...
溶液 - 甚至认为依赖是我做过的 npm安装 然后 dhcp7641:merchant_center sbell10 $ npm install npm WARN package.json依赖项'grunt-castle'存在于依赖项和devDependencies中,使用来自依赖项的'grunt-castle@^0.4.4' lazo-mocks@0.1.2 node_modules / lazo-mocks
chai-jquery@1.2.3 node_modules / chai-jquery
然后开始工作 dhcp7641:merchant_center sbell10 $ grunt copy-bundle;咕噜 运行“cpf_app:tempo:merge”(cpf_app)任务
运行“copy:cpf”(复制)任务 创建了8个目录,复制了5465个文件
运行“copy:app”(复制)任务 创建了2个目录,复制了3496个文件
运行“merge-conf”任务
运行“cpf_app:tempo:bundle-js”(cpf_app)任务