node.js - Heroku上的应用程序不断崩溃

时间:2014-02-27 17:37:45

标签: node.js mongodb heroku mlab

我习惯了localHost dev,并且是生产开发的新手,我正在努力让一个应用程序在Heroku上运行

按照Heroku的“入门”指南中的步骤进行操作..

heroku ps
=== web (1X): `node app.js`
web.1: crashed 2014/02/27 12:27:37 (~ 11m ago)

它可能是我的MongoLab连接代码吗?

var mongodb = require('mongodb');

var uri = 'mongodb://user:pass@host:port/db'
//substituted the user, pass, host, port, and db for my actual parameters

mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } }, function (err, db) {
    var db = this.db('myFirstDemo');
});

我使用上面的代码替换了下面显示的localHost连接代码,基于can't connect to mongolab with node.js on heroku

var MongoClient = require('mongodb').MongoClient;
var Server = require('mongodb').Server;

var mongoclient = new MongoClient(new Server('localhost', 27017,
                                                { 'native_parser' : true }));
var db = mongoclient.db('myFirstDemo');


mongoclient.open(function (err, mongoclient) {
    if (err) throw err
    app.listen(9999);
    console.log("Express server started on port 9999");
});

0 个答案:

没有答案