{"id":22994385,"url":"https://github.com/amreshpro/urlshortner","last_synced_at":"2025-04-02T12:41:35.212Z","repository":{"id":265517975,"uuid":"896178009","full_name":"amreshpro/urlshortner","owner":"amreshpro","description":"A urlshortner api created by using expressjs","archived":false,"fork":false,"pushed_at":"2024-11-30T09:00:49.000Z","size":224,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T03:42:49.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amreshpro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T17:55:11.000Z","updated_at":"2024-11-30T09:00:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"78de2710-4d25-4e7b-9a87-61857d415d46","html_url":"https://github.com/amreshpro/urlshortner","commit_stats":null,"previous_names":["amreshpro/urlshortner"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amreshpro%2Furlshortner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amreshpro%2Furlshortner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amreshpro%2Furlshortner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amreshpro%2Furlshortner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amreshpro","download_url":"https://codeload.github.com/amreshpro/urlshortner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819741,"owners_count":20839094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T05:18:14.895Z","updated_at":"2025-04-02T12:41:35.197Z","avatar_url":"https://github.com/amreshpro.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener Express.js\n\nThis is a simple URL shortener built with **Express.js** and **MongoDB**. It allows you to shorten long URLs, retrieve original URLs from shortened versions, and set expiration dates for URLs.\n\n## Features\n\n- Shorten long URLs\n- Custom aliases for shortened URLs\n- URL expiration feature\n- Redirect to original URLs via short link\n- View all shortened URLs\n\n## Technologies Used\n\n- **Node.js** (Runtime environment)\n- **Express.js** (Web framework)\n- **MongoDB** (Database)\n- **Mongoose** (MongoDB ORM)\n- **NanoID** (For generating unique short IDs)\n\n## Installation\n\n1. **Clone the repository:**\n\n   ```bash\n   git clone https://github.com/amreshpro/url-shortener-express.git\n   ```\n\n2. **Navigate to the project directory:**\n\n   ```bash\n   cd url-shortener-express\n   ```\n\n3. **Install dependencies:**\n\n   Make sure you have **Node.js** and **npm** installed on your system. Install the required packages by running:\n\n   ```bash\n   npm install\n   ```\n\n4. **Set up environment variables:**\n\n   Create a `.env` file in the root directory and configure the following:\n\n```env\nPORT=3000\nNODE_ENV=dev\nDATABASE_URL=dburl\nJWT_SECRET=my-jwt-secret\n ```\n\n   You can change the MongoDB URI to use a remote MongoDB service if required.\n\n5. **Start the server:**\n\n   ```bash\n   npm start\n   ```\n\n   The application will start running on `http://localhost:5000`.\n\n---\n\n## API Endpoints\n\n### 1. **POST** `/api/urls`\n\nCreate a shortened URL.\n\n#### Request Body:\n```json\n{\n  \"originalUrl\": \"https://example.com\",\n  \"alias\": \"customAlias\",  // Optional\n  \"expiration\": \"2024-12-31T23:59:59\" // Optional, ISO format date\n}\n```\n\n#### Response:\n```json\n{\n  \"shortUrl\": \"http://localhost:5000/customAlias\",\n  \"originalUrl\": \"https://example.com\"\n}\n```\n\n---\n\n### 2. **GET** `/api/urls`\n\nGet all shortened URLs.\n\n#### Response:\n```json\n[\n  {\n    \"originalUrl\": \"https://example.com\",\n    \"shortId\": \"customAlias\",\n    \"expiresAt\": null\n  },\n  {\n    \"originalUrl\": \"https://google.com\",\n    \"shortId\": \"abc123\",\n    \"expiresAt\": \"2024-12-31T23:59:59\"\n  }\n]\n```\n\n---\n\n### 3. **GET** `/api/urls/:id`\n\nRedirect to the original URL from the short URL. If the URL has expired, you will get an error.\n\n#### Response:\n- **If found and not expired:** Redirects to the original URL.\n- **If expired:** \n  ```json\n  {\n    \"error\": \"URL has expired\"\n  }\n  ```\n- **If not found:** \n  ```json\n  {\n    \"error\": \"URL not found\"\n  }\n  ```\n\n---\n\n## Testing the API\n\nYou can use **Postman** or **cURL** to test the API:\n\n### Create a Short URL:\n\n- **POST** `/api/urls`\n  \n  Example request:\n  ```json\n  {\n    \"originalUrl\": \"https://example.com\",\n    \"alias\": \"short1\",\n    \"expiration\": \"2024-12-31T23:59:59\"\n  }\n  ```\n\n### Retrieve All URLs:\n\n- **GET** `/api/urls`\n\n### Redirect to Original URL:\n\n- **GET** `/api/urls/short1`\n\n---\n\n## Running\n\n\n**Build**\n\n   ```bash\n  bun run build\n   ```\n\n**Run**\n The application will be accessible at `http://localhost:3000`.\n\n---\n\n\n\n\n### **Contact**\n\nFor any queries, feel free to reach out:\n\n- **GitHub**: [amreshpro](https://github.com/amreshpro)\n- **Email**: [amresh.terminal@gmail.com](mailto:amresh.terminal@gmail.com)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famreshpro%2Furlshortner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famreshpro%2Furlshortner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famreshpro%2Furlshortner/lists"}