0.0.4 • Published 3 years ago

superbatu v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Superbatu - A Custom URL Shortener

Supebatu helps you build your own URL shortener. The idea is to create your own URL shortening database and host it over expressjs app.

Setup

Install

npm install --save superbatu

Add variables in the ‘.env’ file in the root dir of your service

Superbatu needs a mongo connection, which can be defined with the below configs in .env

SUPERBATU_MONGO_USER="your-mongo-user"
SUPERBATU_MONGO_PASSWORD="your-mongo-pass"
SUPERBATU_MONGO_HOST="your-mongo-host"
SUPERBATU_MONGO_PORT="your-mongo-port"
SUPERBATU_MONGO_DATABASE="your-db-name"
SUPERBATU_MONGO_COLLECTION="your-collection-name"

How to use

create a short url

import { createShortUrl } from 'superbatu';
const { uid, url } = await createShortUrl('https://www.yoursuperlong.url')

uid(a unique identifier for url) and url original URL.

Serve short URL with expressjs

import { shortUrlHandler } from 'superbatu';

const router = express();
router.use('/surl/:uid', shortUrlHandler)

It will redirect to the original long URL.