URL Shortener
đĄ Overview
This project bridges DSA/DBMS knowledge into real system design â you'll combine a database, an encoding scheme, and basic web routing into one working product.
â Features to Build
0/4 doneđ§ Step-by-Step Guide
Set up a simple database table: urls(id AUTO_INCREMENT, long_url, short_code).
When a long URL is submitted, insert it and get back its auto-generated ID.
Convert that ID into a short base-62 string (using characters a-z, A-Z, 0-9) to use as the short_code.
Build a route like /:code that looks up the code in the database and issues a redirect to the long_url.
Add a check: if the same long URL is submitted again, return the EXISTING short code instead of creating a duplicate.
đ Starter Code
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
function encodeBase62(num) {
let code = '';
while (num > 0) {
code = chars[num % 62] + code;
num = Math.floor(num / 62);
}
return code || '0';
}đĄ Pro Tip
Start with the database ID â base62 encoding working correctly in isolation (test it with plain numbers) before wiring up the actual web server and redirect logic around it.