This is a robust URL shortening application built using Node.js, Typescript Express, MongoDB, and EJS.
The URL shortening application allows users to shorten long URLs into short, easy-to-share links. The application provides a user-friendly interface where users can input their long URLs, and the application generates a shortened version for easy sharing.
- Shorten long URLs into short, easy-to-share links.
- User-friendly interface with instant feedback for shortened URLs.
- Security features like Rate Limiting and Content Security Policy (CSP) to prevent abuse and enhance security.
- Redirects users to the original long URL when they access the shortened link.
- Responsive design for a seamless experience on various devices.
- Clone this repository to your local machine:
git clone https://github.com/your-username/url-shortener.git
cd url-shortener
- Install the required dependencies:
npm install
OR
yarn install
- Set up the environment variables:
Rename the
.env.example
file in the root directory to.env
and provide the necessary configuration. For example:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/url_shortener_db
BASE_URL=http://localhost:3000
- Start the application:
npm run start
OR
yarn run start
- Access the application by navigating to https://localhost:3000 in your web browser.
- Enter a long URL in the input field and click the "Shorten" button.
- The application will generate a shortened URL, which you can copy and share.
The application also provides API endpoints to programmatically shorten URLs and access the redirection information.
-
Shorten a URL
POST /v1/shorten Request Body: { "longUrl": "https://www.example.com/some/long/url" } Response: { "shortUrl": "http://localhost:3000/s/abc123" }
-
Redirect to the Original URL
GET /v1/shorten/:code Response: Redirects to the original long URL
This project is licensed under the MIT License.