A simple URL shortener service built with Node.js, Express, MongoDB, and Mongoose.
- Generate short URLs from long URLs
- Redirect short URLs to the original URLs
- Store URLs in MongoDB
- Simple server-side rendering with EJS (optional)
- Node.js (v14 or later recommended)
- MongoDB running locally or remotely
-
Clone the repository:
git clone https://github.com/saikrishna1355/url-shortener.git cd url-shortener
-
Install dependencies:
npm install
-
Start the server:
npm start
Create a short URL.
Request body:
{
"originalUrl": "https://example.com/long-url"
}
Response:
{
"originalUrl": "https://example.com/long-url",
"shortUrl": "http://localhost:3000/shortCode"
}
Redirects to the original URL.