开发者

nodejs chat example does not work

开发者 https://www.devze.com 2023-02-24 05:27 出处:网络
I\'ve come across a node chat example on github, When I try to run it, I see the following error: Error connecting to mongo perhaps it isn\'t running ?

I've come across a node chat example on github, When I try to run it, I see the following error:

Error connecting to mongo perhaps it isn't running ?

I've installed mongo 0.9.2, nodejs 5开发者_开发问答.2 pre, npm 3.0 and other dependencies. The example can be found here: https://github.com/gregstewart/chat.io

I can not determine whether if the example not really works or I didn't run it right. Please help.


Did you install and start mongo-db on your system? This error is mostly because of a missing mongo instance running on the local machine.

Check out the follwing code excerpts from chat.io.

main.js:

/**
* Configure the user provider (mongodB connection for user data storage)
*/
var userProvider = new UserProvider('localhost', 27017);

Creates a new UserProvider object using host and port for database (localhost:27017, mongo-db default).

UserProvider.js:

UserProvider = function(host, port) {
    this.db = new mongo.Db('node-mongo-chat', new Server(host, port, {auto_reconnect: true}, {}));
    this.db.addListener('error', function(error) {
      console.log('Error connecting to mongo -- perhaps it isn\'t running?');
    });
    this.db.open(function() {
    });
};

Opening the connection to the server, printing out an error on failure (the error you mentioned above).

Consider reading up on the mongo-db docs concerning installation and setup here

0

精彩评论

暂无评论...
验证码 换一张
取 消