Supebatu helps you build your own URL shortener. The idea is to create your own URL shortening database and host it over expressjs
app.
npm install --save superbatu
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"
import { createShortUrl } from 'superbatu';
const { uid, url } = await createShortUrl('https://www.yoursuperlong.url')
uid
(a unique identifier for url) and url
original URL.
import { shortUrlHandler } from 'superbatu';
const router = express();
router.use('/surl/:uid', shortUrlHandler)
It will redirect to the original long URL.