An open API service indexing awesome lists of open source software.

https://github.com/thedevelop3r/url-shortner

this project was a challenge at freecodecamp for url shortning | i used mongoose as database some extra packages and wrote its logic , passed the test
https://github.com/thedevelop3r/url-shortner

Last synced: 12 months ago
JSON representation

this project was a challenge at freecodecamp for url shortning | i used mongoose as database some extra packages and wrote its logic , passed the test

Awesome Lists containing this project

README

          

# URL Shortener Microservice

This is the boilerplate code for the URL Shortener Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice.

---

# URL Shortener

This project is a solution to a FreeCodeCamp challenge for building a URL shortener service. It uses Node.js, Express, and MongoDB (via Mongoose) to provide a simple web API for shortening URLs. The application includes additional logic and packages to meet challenge requirements and all tests have been passed.

## Features

- Shorten long URLs to concise short links
- Store and retrieve URLs using MongoDB with Mongoose
- RESTful API endpoints
- Fully passes FreeCodeCamp test suite

## Getting Started

### Prerequisites

- Node.js (v14 or later)
- npm
- MongoDB (local or Atlas)

### Installation

1. **Clone the repository:**
```bash
git clone https://github.com/Thedevelop3r/url-shortner.git
cd url-shortner
```

2. **Install dependencies:**
```bash
npm install
```

3. **Set up environment variables:**

Create a `.env` file in the root directory and add your MongoDB URI:
```
MONGO_URI=your_mongodb_connection_string
PORT=3000
```

4. **Start the application:**
```bash
npm start
```
The server will run on `http://localhost:3000` by default.

## API Endpoints

- **POST `/api/shorturl`**
- Request Body: `{ "url": "https://example.com" }`
- Response: `{ "original_url": "https://example.com", "short_url": 1 }`

- **GET `/api/shorturl/:short_url`**
- Redirects to the original URL corresponding to the provided short URL code.

## Technologies Used

- JavaScript (Node.js, Express)
- MongoDB & Mongoose
- CSS (for any frontend)
- Shell scripts (for automation tasks)

## License

This project is open-source and available under the [MIT License](LICENSE).