npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@the-node-forge/url-shortener

v1.0.0

Published

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

Downloads

10

Readme

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

Resolve a Link

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

📘 API Reference

new URLShortener(baseDomain, store)

| Parameter | Type | Required | Description | | ------------ | -------------- | -------- | ------------------------------- | | baseDomain | string | ❌ | Domain to prefix for short URLs | | store | StoreAdapter | ✅ | Instance of RedisStore |

shorten(longUrl, options?)

| Option | Type | Required | Description | | ----------- | --------- | -------- | ---------------------------------- | | longUrl | string | ✅ | The URL to shorten | | alias | string | ❌ | Custom code (e.g., "my-link") | | expiresIn | string | ❌ | TTL like "1h", "30m", "7d" | | override | boolean | ❌ | Replace 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)

| Store | Runtime | Notes | | ---------- | ------------ | ---------------------------------- | | RedisStore | ✅ Node-only | Requires 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!


🔗 Links