short
Node.js URL Shortener backed by Mongoose.js
No Callbacks, just Promises!
Installation
$ npm install short
Basic API Usage
Generates a Shortened URL Doc, then retrieves it for demo:
var shortURLPromise short = ; // connect to mongodbshort; shortconnection; // promise to generate a shortened URL.var shortURLPromise = short; // gets back the short url document, and then retrieves itshortURLPromise;
Listing all Shortened URLs in DB:
var listURLsPromise short = ; // connect to mongodbshort; shortconnection; // promise to retrieve all shortened URLslistURLsPromise = short; // output all resulting shortened url db docslistURLsPromise;
Updating the URL or the data fields of an existing Short URL hash
// Basically, update works like thisvar updatePromise = short;// hash => Short url hashcode generated using short.generate()// updateData => An object consisting of the new URL and/or the new data object. // If a key already exists in the current data object, it's value is updated, // otherwise, it is added and saved to the data object //This function returns a promise which on resolution returns the new updated object as an argument.
Here's some working code. hash
is assumed to be given
// The basic Initialisation, Connection, Short URL generation and // retrieval remains the same as depicted in previous examples // the variable hash contains the short url hash code generated using short.generate()var updatePromise = short;updatePromise;
Contribute
- Fork
- Clone forked repository
- Add some sweet code
- Tests still passing? Run tests with
npm test
- Add a test if adding a feature
- Pull Request
- Instant Karma!
License (MIT)
Copyright (c) 2011-2013, Edward Hotchkiss.