A simple URL shortener built with Node.js, Express, MongoDB, and a plain HTML/CSS frontend.
- Shortens long URLs to compact codes
- Redirects users to the original URL
- Simple REST API (
/api/shorten
and/:shortURL
) - Frontend using plain HTML, CSS, and JavaScript
- MongoDB containerized with Docker
git clone https://github.com/your-username/url-shortener.git
cd url-shortener
Run the command below to spin up MongoDB:
docker run -d --name mongodb -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=user -e MONGO_INITDB_ROOT_PASSWORD=password mongo
cd backend
PORT=3000
MONGO_URI=mongodb://user:password@localhost:27017/ni?authSource=admin
npm install
npm start
Server will be running at:
http://localhost:3000
You have a few options:
Double-click frontend/index.html
or open it in your browser.
cd frontend
python -m http.server 8080
Visit:
http://localhost:8080
Install globally:
npm install -g live-server
Then:
cd frontend
live-server
Request:
{
"originalURL": "https://example.com"
}
Response:
{
"shortURL": "abcde"
}
Visit http://localhost:3000/abcde
to be redirected.
docker stop mongodb
docker rm mongodb
url-shortener/
├── backend/
│ ├── server.js
│ ├── package.json
│ └── .env
├── frontend/
│ ├── index.html
│ └── style.css
├── LICENSE
├── README.md
└── .gitignore
MIT