Same project, different language. Learning by rebuilding the same thing multiple times in different programming languages.
- POST a long URL to
/shortenor use the frontend form - Get back a short URL
- Visit
/{shortCode}for redirection to the original URL
git clone https://github.com/robiverdev/urlshortenerjs
cd urlshortenerjs
npm install
node server.jsServer starts on http://localhost:4000
Shorten a URL:
curl -X POST -H "Content-Type: application/json" -d '{"originalUrl":"https://google.com"}' http://localhost:4000/shortenResponse example: {"shortUrl":"http://localhost:4000/4aGewg"}
Visit the short URL:
http://localhost:4000/4aGewg
Redirects to the original URL.
- Building HTTP servers with Express
- Handling JSON POST requests and parsing request bodies
- Generating unique short codes with nanoid library
- Using in memory storage with JavaScript objects
- Implementing HTTP redirects using Express
- Serving static frontend files with Express middleware
- Connecting frontend to backend using the Fetch API
- Minimal CSS styling for user friendly display