new URLShortener(mongodb, error, url)
URL Shortener class object
Initialize URL Shortener Object
Parameters:
Name | Type | Description |
---|---|---|
mongodb |
object | connection url |
error |
function | callback |
url |
object | shortener configuration object |
Example
const URLShortener = require('node-short-url');
const options = {
characters: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
minHashCount: "4",
domain: "click.com"
}
const shortUrl = new URLShortener(mongodb, errorCallback, options);
Methods
retrieve(hash) → {String}
Takes hash string parameters
Retrieve actual url from hash
Parameters:
Name | Type | Description |
---|---|---|
hash |
String | shortened url hash |
Returns:
returns long url of hash
- Type
- String
Example
const shortUrl = new URLShortner('mongodb://192.168.0.161/shortdb', (err) => console.log(err), { domain: 'https:click.com' });
shortUrl.retrieve('0004')
.then(res => console.log('res' , res))
.catch(err => console.log(err));
shortenUrl(url, expiry) → {object}
Takes 2 string parameters url and expiry date.
Generates and returns shortURL
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL to be shortened |
expiry |
Date | Date when url will expire |
Returns:
returns object with shortened url
- Type
- object
Example
const shortUrl = new URLShortner('mongodb://192.168.0.161/shortdb', (err) => console.log(err), { domain: 'https:click.com' });
shortUrl.shortenUrl('https://client.example.com/user/1', new Date("2025-02-01"))
.then(res => console.log('res' , res))
.catch(err => console.log(err));