New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-url-shortener

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-url-shortener

mongoose-url-shortener

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

###MongooseURLShortener

Please Share on Twitter if you like #MongooseURLShortener

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

####Installation

npm install mongoose-url-shortener --save

####API

//Setup Mongoose
var connection = require('mongoose').connect('mongodb:testing');
//Initialize Shortener
var urlShotener = MongooseURLShortener(connection, options);

#####Options { seed:12345, schema: { customSchemaValue:Number, customSchemaObj:{} } } 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 Shorten will either create a new short url in your database or resolve to a previously shortened URL.

url = 'http://www.google.com';
data = { 'any data you want to record with the short url' : true }
var promise = urlShortener.shorten(url, data);
promise.then(function(url){
    console.log(url.hash);
    //aGasjn1Ho
}).fail(function(err){
    console.error('Error creating short url', err);
});

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

hash = 'aGasjn1Ho';
data = {ip:'127.0.0.1'};
var result = urlShotener.resolve(hash, data);
result.then(function(url){
console.log(url );
// { 
//    type: 'MongooseURLShortener', 
//    url: 'http://www.google.com', 
//    hash:'aGasjn1Ho',
//    hits:{
//        {ip:'127.0.0.1},
//        {ip:'127.0.0.1},
//    },
//    totalHits: 2
//}
}).fail(function(err){});

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

Keywords

FAQs

Package last updated on 19 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc