Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mongoose.connection.on(open|error)

  • Loading branch information...
commit e94fa7226854670e431481ac123ec182ad45112f 1 parent db5806b
Edward Hotchkiss authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/short.js
View
9 lib/short.js
@@ -33,6 +33,12 @@ function hasher(URL) {
exports.connect = function (mongodb) {
mongoose.connect(mongodb);
+ mongoose.connection.on('open', function(){
+ console.log('mongodb connected');
+ });
+ mongoose.connection.on('error', function(error){
+ throw new Error(error);
+ })
};
/*!
@@ -43,7 +49,6 @@ exports.connect = function (mongodb) {
exports.gen = function (URL, callback) {
var hashedURL = hasher(URL);
-
var item = new ShortURL({
URL : URL,
hash : hashedURL
@@ -51,7 +56,7 @@ exports.gen = function (URL, callback) {
item.save(function (error, item) {
//Tries to save to mongodb, if it exists it retries
if (error && error.code === 11000) {
- console.log(hashedURL + " already exists! Retrying!");
+ console.log(hashedURL + ' already exists! Retrying!');
short.gen(URL, callback);
} else {
callback(null, item);
Please sign in to comment.
Something went wrong with that request. Please try again.