A full stack URL shortener with click analytics. No external dependencies or database installs required — it runs with just Node.js.
- Shorten any valid
http(s)URL into a short code - Optional custom short codes (e.g.
/my-link) - Click tracking per link
- List, view, and delete existing links
- Clean, responsive UI (no frontend framework/build step needed)
- Backend: Node.js core
httpmodule (no Express) — seeserver.js - "Database": a local
db.jsonfile, created automatically on first run - Frontend: plain HTML/CSS/JS in
public/
Everything runs with plain node, so there's nothing to install.
node server.jsThen open http://localhost:3000 in your browser.
That's it — db.json will be created automatically the first time you shorten a link.
(You can also run npm start, which does the same thing.)
url-shortener/
├── server.js # HTTP server, routing, and all API logic
├── package.json
├── db.json # created automatically — your data lives here
└── public/
├── index.html # page structure
├── style.css # styling
└── script.js # frontend logic (fetch calls, DOM updates)
| Method | Route | Description |
|---|---|---|
| POST | /api/shorten |
Create a short URL. Body: { url, customCode? } |
| GET | /api/urls |
List all short URLs |
| GET | /api/urls/:code |
Get details/stats for one short code |
| DELETE | /api/urls/:code |
Delete a short URL |
| GET | /:code |
Redirect to the original URL (increments click count) |
curl -X POST http://localhost:3000/api/shorten \
-H "Content-Type: application/json" \
-d '{"url":"https://www.example.com/some/very/long/path"}'Response:
{
"shortCode": "aB3xQ9",
"shortUrl": "http://localhost:3000/aB3xQ9",
"originalUrl": "https://www.example.com/some/very/long/path"
}- Swap
db.jsonfor a real database (SQLite viabetter-sqlite3, Postgres, etc.) once you have npm access — the storage logic is isolated inloadDB()/saveDB()inserver.js, so it's a contained change. - Add user accounts so people can manage only their own links
- Add link expiration dates
- Generate a QR code for each short link
- Add basic rate limiting to
/api/shorten - Track referrer/location data on each click for richer analytics