Please Share on Twitter if you like #MongooseURLShortener

A simple URL Shortening library for NodeJS using Promises/A+ results.

npm install mongoose-url-shortener --save
//Setup Mongoose
var connection = require('mongoose').connect('mongodb:testing');
//Initialize Shortener
var urlShotener = MongooseURLShortener(connection, options);
    schema: {

Seed Optional value to use for generating short url's. You must always use the same seed otherwise you will not be able to resolve short urls' back to their original url.

Schema Optional schema properties for the Mongoose object. You can then pass the extra values you define here to be saved along with the URL when shortening or resolving

Shorten will either create a new short url in your database or resolve to a previously shortened URL.

url = '';
data = { 'any data you want to record with the short url' : true }
var promise = urlShortener.shorten(url, data);
    console.error('Error creating short url', err);

Resolve will return the original URL before shortening if one is available in the database.

hash = 'aGasjn1Ho';
data = {ip:''};
var result = urlShotener.resolve(hash, data);
console.log(url );
// { 
//    type: 'MongooseURLShortener', 
//    url: '', 
//    hash:'aGasjn1Ho',
//    hits:{
//        {ip:'},
//        {ip:'},
//    },
//    totalHits: 2

data is an optional object you would like to be saved with each resolution of a URL and can be used for such things as analytics tracking.

Check out NodeTinyUrl for a working implementation

Please Share on Twitter if you like #MongooseURLShortener