shorten-ly
v0.0.2-alpha
Published
π A simple URL shortener library with Express & SQLite
Downloads
11
Readme
shorten-ly π - A Simple URL Shortener Library
shorten-ly is a lightweight Node.js library that lets you shorten URLs, retrieve original links, and track analytics using SQLite.
β¨ Features
- β Shorten long URLs into compact links
- β Retrieve the original URL from a shortened link
- β Track visit analytics for each short link
- β Use SQLite for persistence (supports both file-based and in-memory storage)
- β Customize your domain for shortened links
π¦ Installation
Install the package using npm or yarn:
npm install shorten-ly
# or
yarn add shorten-lyπ Usage
1οΈβ£ Import the Library
import { urlShortener } from "shorten-ly";2οΈβ£ Set a Custom Domain (Optional)
By default, shorten-ly uses http://localhost:3000, but you can set your own domain:
urlShortener.setBaseURL("https://mycustomdomain.com");If you skip this step, the default http://localhost:3000 will be used.
3οΈβ£ Shorten a URL
(async () => {
const shortURL = await urlShortener.shortenURL(
"https://example.com/long-url"
);
console.log(shortURL); // e.g., https://mycustomdomain.com/abc123
})();4οΈβ£ Retrieve the Original URL
const originalURL = await urlShortener.getOriginalURL("abc123");
console.log(originalURL); // https://example.com/long-url5οΈβ£ Get URL Analytics (Visit Count)
const analytics = await urlShortener.getAnalytics("abc123");
console.log(`Visits: ${analytics.visits}`);π Folder Structure
shorten-ly/
βββ prisma/
β βββ schema.prisma
β βββ prisma.db (SQLite database)
βββ src/
β βββ index.js
βββ example.js
βββ .gitignore
βββ package.json
βββ README.mdπ Database Configuration
shorten-ly uses SQLite for storage. By default, it saves data in prisma.db.
Run:
npx prisma migrate dev --name initπ― Why Use shorten-ly?
β No external services required - Everything runs locally
β Custom domain support - Use your own short link domain
β Easy integration - Works as a library in your existing projects
Contributing
Feel free to contribute by submitting issues or pull requests.
π License
This project is licensed under the MIT License.
π¨βπ» Author
Developed by Parth Sharma
