shortlnk

1.1.2 • Public • Published

shortlnk

NPM Version

License

shortlnk is an npm package that provides functions for shortening URLs and decoding shortened URLs. It allows you to create short, memorable URLs for your long links and easily retrieve the original URLs from the shortened versions.

Features

  • Shorten long URLs to create shorter, more user-friendly links.
  • Decode shortened URLs to retrieve the original long URLs.
  • Simple and easy-to-use Package for generating and decoding short URLs.
  • Works with any valid HTTP/HTTPS URL.
  • Public and free to use.

Installation

Install the shortlnk package via npm:

npm install shortlnk

Usage

Here's an example of how to use shortlnk to create and decode short URLs:

const { createShortUrl, decodeURL } = require('shortlnk');

async function testShortlnk() {
  try {
    const longUrl = 'https://www.youtube.com';

    // Create a short URL
    const createResponse = await createShortUrl(longUrl);
    if (createResponse.success) {
      console.log('Short URL:', createResponse.data);
    } else {
      console.error('Error creating short URL:', createResponse.error);
    }

    const shortUrl = 'j08KMQtWUC';

    // Decode a short URL
    const decodeResponse = await decodeURL(shortUrl);
    if (decodeResponse.success) {
      console.log('Decoded URL:', decodeResponse.data);
    } else {
      console.error('Error decoding short URL:', decodeResponse.error);
    }
  } catch (err) {
    console.error('An error occurred:', err);
  }
}

testShortlnk();

Notes

  • The shortlnk package uses a free server hosting service onrender and MongoDB for the database.
  • Each long URL is mapped to a unique short ID.
  • All the short URLs generated using shortlnk are public and can be accessed by anyone.
  • http+s urls are allowed only.

Links

Package Sidebar

Install

npm i shortlnk

Weekly Downloads

24

Version

1.1.2

License

ISC

Unpacked Size

12.6 kB

Total Files

4

Last publish

Collaborators

  • harshmp