DEV Community

sanjay kumar
sanjay kumar

Posted on

How I Built a URL Shortener Using Node.js, Redis, Docker & Deployed It on Render

πŸ‘‹ A Quick Backstory
Hey everyone, I’m Sanjay β€” a self-taught dev who loves building from scratch and learning by doing. I recently went deep into DevOps and containerization, and this URL shortener project was my way of exploring Redis, Docker, and cloud deployment β€” all in one shot.

This project was never about just shortening URLs. For me, it was about:

Learning how to structure a scalable backend 🧱

Working with Redis as a primary data store 🧠

Deploying real-world projects with Docker + Render πŸš€

It’s simple on the surface, but I learned a ton building this. Here's the breakdown πŸ‘‡

Preview Image

πŸ”— URL Shortener – Node.js, Redis & Docker

A full-stack, production-grade URL shortening service built with Node.js, Express, Redis, and Docker β€” complete with a RESTful API, unit tests, containerization, and cloud deployment on Render.


🌍 Live Demo

🟒 Deployed on Render
Frontend: Static HTML + JS
Backend: Node.js + Redis
Dockerized with Dockerfile and nginx (for local use)


🧰 Tech Stack

  • Frontend: HTML, JavaScript (Vanilla)
  • Backend: Node.js + Express
  • Database: Redis (for storing shortened URLs)
  • Testing: Jest
  • DevOps: Docker, Render, NGINX
    (Experimental): Rate Limiting, GitHub Actions (CI)

    • Docker & docker-compose (for local development)
    • Render (for cloud deployment)
    • NGINX (proxy for local routing)

πŸ“ Project Structure

05sanjaykumar-url-shortern/
β”œβ”€β”€ public/             # Static frontend (HTML + JS)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js          # Main app setup
β”‚   β”œβ”€β”€ controllers/    # Shorten & redirect logic
β”‚   β”œβ”€β”€ middleware/     # Rate limiting (dummy)
β”‚   β”œβ”€β”€ routes/         # API endpoints
β”‚   └── services/       # Redis logic + URL generation
β”œβ”€β”€ test/               # Unit tests + Redis mocks
β”œβ”€β”€ nginx/              # NGINX config (for local Docker)
β”œβ”€β”€ .github/workflows/  # CI pipeline (placeholder)
β”œβ”€β”€ Dockerfile + docker-compose.yml
β”œβ”€β”€ server.js
└── .env-example
Enter fullscreen mode Exit fullscreen mode

βœ… Features

  • πŸ”— Shortens long URLs to unique 6-character codes
  • πŸš€ Redirects to original URLs
  • 🧠 Stores URL mappings in Redis
  • πŸ§ͺ Unit-tested with mocked Redis interactions
  • πŸ› οΈ Includes a basic demo rate limiter (not production-grade)
  • 🐳 Local Docker support
  • 🌐 Fully deployed backend + frontend on Render

βš™οΈ Running Locally

Option 1: Docker (recommended)

docker-compose up
Enter fullscreen mode Exit fullscreen mode

Then open: localhost

(OR)

Option 2: Manual

git checkout render-deploy
npm install
redis-server
npm start
Enter fullscreen mode Exit fullscreen mode

Then open: http://localhost:3000


πŸ§ͺ Run Tests

npm test
Enter fullscreen mode Exit fullscreen mode

Tests include mocked Redis functionality for isolated unit testing.


πŸ“¦ Deployment (Render)

The app is deployed using Render:

  • Backend connects to Redis
  • Frontend served statically (via nginx or Render)
  • Base URL is dynamically handled in production

πŸ“Œ Learnings

  • πŸ“¦ Designed modular Express backend (routes, controllers, services)
  • πŸ§ͺ Wrote unit tests with Redis mocks
  • 🐳 Containerized with Docker + Docker Compose
  • πŸš€ Deployed on Render (frontend + backend)
  • πŸ› οΈ Explored how rate limiting works in Express (demo-only)
  • 🌱 Gained deeper insight into app structure, devops, and deployment

⚠️ Note: The rate limiter is a basic, demonstration-only middleware. For real-world production use, consider packages like express-rate-limit or Redis-backed implementations.


πŸ™Œ Author

Sanjay Kumar β€” Lifelong learner, and builder of things.
GitHub Repo

Top comments (0)