
The Node Forge presents:
A simple and flexible URL shortener package for JavaScript/TypeScript applications. This package helps developers create branded or custom short URLs for their projects.
✨ Features
- ✅ Custom Aliases – Shorten with a readable slug.
- ✅ Expiration Support – Set TTL for each link.
- ✅ Self-hostable – Use with your own Express backend.
- ✅ Frontend-Friendly – Call via API from client apps.
📦 Installation
npm install @the-node-forge/url-shortener
or using Yarn:
yarn add @the-node-forge/url-shortener
🛠️ Basic Usage
1️⃣ 🌐 JavaScript/TypeScript Example
import { shortenUrl } from '@the-node-forge/url-shortener';
(async () => {
const shortUrl = await shortenUrl('https://example.com/some/long/path', {
alias: 'launch',
expiresIn: '7d',
});
console.log(shortUrl); // Output: https://sho.rt/launch
})();
2️⃣ 🌐 Express Integration Example
import express from 'express';
import { shortenUrl } from '@the-node-forge/url-shortener';
const app = express();
app.use(express.json());
app.post('/shorten', async (req, res) => {
const { url, options } = req.body;
try {
const shortUrl = await shortenUrl(url, options);
res.json({ shortUrl });
} catch (err) {
res.status(400).json({ error: err.message });
}
});
app.listen(3000, () => console.log('URL shortener running on port 3000'));
✅ API Reference
shortenUrl Function
shortenUrl(longUrl: string, options?: {
alias?: string;
expiresIn?: string;
}): Promise<string>
Parameter | Type | Description |
---|---|---|
longUrl | string | The original URL to be shortened |
alias | string | Optional custom slug for the shortened URL |
expiresIn | string | Optional TTL for the short link (e.g. "7d") |
Returns
Promise<string>
– The generated shortened URL.
💡 Contributing
Contributions are welcome! Please submit issues or pull requests.
⭐ Support
If you find this package useful, please give it a ⭐ on GitHub