Socket
Book a DemoInstallSign in
Socket

@the-node-forge/url-shortener

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@the-node-forge/url-shortener

A URL shortener that generates and stores unique aliases for long URLs, with optional expiration and custom alias support.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
11
83.33%
Maintainers
3
Weekly downloads
 
Created
Source

URL Shortener

License: MIT

Made with TypeScript

NPM Version Build Status Platform

Live Documentation

A simple, fast, and Redis-backed URL shortener written in TypeScript. Supports custom aliases, TTL expiration, and works seamlessly in Node.js environments.

✨ Features

  • Custom Aliases – Define readable slugs like sho.rt/launch
  • Expiration Support – Auto-expire short links after a set TTL
  • Redis Store – High-performance storage backend
  • 🔀 Collision Handling – Auto-generate or error on alias conflicts
  • 📚 Fully Typed – TypeScript-first design with clean API docs

📦 Installation

npm install @the-node-forge/url-shortener
yarn add @the-node-forge/url-shortener

Redis Required

npm install redis

Redis is required and should be connected externally via createClient()

🛠️ Basic Usage

import { createClient } from 'redis';
import { RedisStore } from '@the-node-forge/url-shortener/stores/redisStore';
import { URLShortener } from '@the-node-forge/url-shortener';

const client = createClient();
await client.connect();

const store = new RedisStore(client);
const shortener = new URLShortener('https://sho.rt', store);

const shortUrl = await shortener.shorten('https://example.com/very/long/url', {
  alias: 'launch',
  expiresIn: '7d',
});

console.log(shortUrl); // https://sho.rt/launch
const result = await shortener.resolve('launch');
console.log(result); // https://example.com/very/long/url

📘 API Reference

new URLShortener(baseDomain, store)

ParameterTypeRequiredDescription
baseDomainstringDomain to prefix for short URLs
storeStoreAdapterInstance of RedisStore

shorten(longUrl, options?)

OptionTypeRequiredDescription
longUrlstringThe URL to shorten
aliasstringCustom code (e.g., "my-link")
expiresInstringTTL like "1h", "30m", "7d"
overridebooleanReplace alias if it already exists

resolve(alias)

Returns the original URL string, or null if expired or missing.

🌍 Environment Compatibility

This package works in modern server-side runtimes:

  • ✅ Node.js
  • ✅ Deno / Bun (with bundler)
StoreRuntimeNotes
RedisStore✅ Node-onlyRequires Redis and redis package

This is a backend utility. Frontend usage is not supported directly — build an API endpoint instead.

💡 Contributing

Contributions welcome! Open an issue or PR if you have improvements, ideas, or bug fixes.

⭐ Support

If you like this project, consider leaving a ⭐ on GitHub!

Keywords

url-shortener

FAQs

Package last updated on 16 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.