backend api nodejs database

URL Shortener API

Build a URL shortening service with analytics, custom aliases, and expiration dates

โฑ๏ธ Time Breakdown

๐Ÿ“‹
Planning
~1 hours
๐Ÿ’ป
Coding
~2 hours
๐Ÿงช
Testing
~1 hours

๐Ÿ“Š Difficulty

easy

๐ŸŽ“ Learning Outcomes

  • โ€ข Working with REST APIs
  • โ€ข Managing application state
  • โ€ข Creating responsive layouts

URL Shortener API

Create a URL shortener API that converts long URLs into short, shareable links with tracking capabilities and optional custom aliases.

Project Checklist

  • Create endpoint to shorten URLs
  • Generate unique short codes for URLs
  • Store mapping between short codes and original URLs
  • Create redirect endpoint that resolves short URLs
  • Add click tracking and analytics
  • Implement custom alias support

Bonus Project Checklist Items

  • Add expiration dates for shortened URLs
  • Implement QR code generation
  • Create analytics dashboard endpoint
  • Add password protection for links
  • Implement bulk URL shortening
  • Add geographic click tracking

Inspiration (Any companies/libraries similar)

  • Bitly
  • TinyURL
  • Short.io

Hint/Code snippet to start

const shortid = require('shortid');

app.post('/shorten', async (req, res) => {
  const { url, customAlias } = req.body;
  const shortCode = customAlias || shortid.generate();
  await db.urls.create({ shortCode, originalUrl: url, clicks: 0 });
  res.json({ shortUrl: `${baseUrl}/${shortCode}` });
});

app.get('/:shortCode', async (req, res) => {
  const url = await db.urls.findOne({ shortCode: req.params.shortCode });
  await db.urls.update({ clicks: url.clicks + 1 });
  res.redirect(url.originalUrl);
});
โ˜ฐ

Project Requirements

Progress Tracker 0 of 7 completed

Share Project