Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A full stack URL shortener with click analytics. No external dependencies or database installs required — it runs with just Node.js.

Features

  • 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)

Tech stack

  • Backend: Node.js core http module (no Express) — see server.js
  • "Database": a local db.json file, created automatically on first run
  • Frontend: plain HTML/CSS/JS in public/

Everything runs with plain node, so there's nothing to install.

Getting started

node server.js

Then 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.)

Project structure

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)

API reference

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)

Example: create a short link

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"
}

Ideas to extend this project

  • Swap db.json for a real database (SQLite via better-sqlite3, Postgres, etc.) once you have npm access — the storage logic is isolated in loadDB() / saveDB() in server.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

About

A full-stack URL Shortener built with Node.js, HTML, CSS, and Vanilla JavaScript using the native Node.js http module (without Express). The application allows users to generate short URLs, create custom aliases, track click analytics, and manage links through a clean and responsive interface.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages