https://github.com/sunjay-dev/url-shortener-using-json-file
URL shortener utilizes a JSON file for storage to create and manage short URLs.
https://github.com/sunjay-dev/url-shortener-using-json-file
Last synced: 4 months ago
JSON representation
URL shortener utilizes a JSON file for storage to create and manage short URLs.
- Host: GitHub
- URL: https://github.com/sunjay-dev/url-shortener-using-json-file
- Owner: sunjay-dev
- License: mit
- Created: 2024-10-20T16:44:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-16T18:30:57.000Z (over 1 year ago)
- Last Synced: 2025-04-07T04:54:22.484Z (about 1 year ago)
- Language: HTML
- Size: 201 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# URL Shortener Using JSON File As Storage
A simple URL shortener built with Node.js and Express.js that stores shortened URLs in a JSON file. This project allows users to create short URLs and redirect to the original URLs.
## Features
- Shorten long URLs and access them using a shorter link.
- Store and manage URL mappings in a JSON file.
- Enhanced Error handling.
## Technologies Used
     
- Node.js
- Express.js
- shortid (For creating short id for url)
- NPM (For downloading dependencies)
- Html/CSS/Javascript (For 404 webpage page)
## Installation
1. Clone the repository:
```bash
git clone https://github.com/sunjay-dev/URL-Shortener-using-json-file/
cd URL-Shortener-using-json-file
npm install
npm start
## Project Structure
- controllers/: Contains the logic for handling requests and responses.
- public/: Holds static files like 404 page.
- data.json: The JSON file used to store short URLs and their corresponding original URLs.
- routes/: Contains information about routes
## Routes
The application provides the following routes:
### GET `/shortid`
- **Description**: Handles requests to the shortened URL and redirects to the original URL.
- **Parameters**:
- `shortId`: The short ID of the URL to redirect.
- **Response**:
- On success, redirects to the original URL.
- If the short ID does not exist, returns a 404 error.
### POST `/`
- **Description**: Creates a new shortened URL.
- **Request Body**:
- `url`: The original URL to be shortened.
- **Response**:
- Returns a JSON object containing the shortened URL.
### POST `/custom`
- **Description**: Creates a new shortened URL with a custom alias.
- **Request Body**:
- `url`: The original URL to be shortened.
- `custom`: The custom alias for the shortened URL.
- **Response**:
- Returns a JSON object containing the shortened URL with the custom alias.
- If the custom alias is already in use, returns an 409 error message.
### GET `/api/details?url=shortId`
- **Description**: Provides details about shortened url.
- **Parameters**:
- `shortId`: The short ID of the URL to retrieve.
- **Response**:
- On success, returns a JSON object containing number of click, original url, and array of lastOpened times.
- If the short ID does not exist, returns a 404 error.
## Contributing
Feel free to submit issues or pull requests if you have suggestions for improvements.