Welcome to the URL Shortener Project! This project aims to provide a simple and efficient URL shortening service.
The URL Shortener Project is designed to create shortened URLs that redirect to the original long URLs. It's built using Node.js, Express, and MongoDB.
- Generate short URLs from long URLs
- Redirect short URLs to the original long URLs
Before getting started, make sure you have the following software installed:
- Node.js (Version 14 or higher)
- MongoDB (Version 4 or higher) [Only required for local or self-hosted MongoDB instances]
To install and set up the project, follow these steps:
- Clone this repository:
git clone https://github.com/con-cis/url-shortener.git
- Navigate to the project directory:
cd url-shortener
- Install dependencies:
npm install
To use the URL shortener service, follow these steps:
- Start the server:
npm start
- Open your web browser and go to:
http://localhost:3000
- Enter a long URL and click "Shorten" to generate a short URL.
- Access the short URL in your browser to be redirected to the original long URL.
You can configure the URL shortener service by modifying the .env
file in the root directory. Copy the .env.example
file to .env
and adjust the values as needed.
The URL Shortener Project follows a simple but effective architecture pattern. It uses the Express framework to handle HTTP requests, and MongoDB with Mongoose for data storage. The application structure includes controllers for URL shortening and redirection, and models to interact with the database.
The project employs comprehensive error handling. Invalid URLs are detected through DNS probing, preventing the generation of short URLs for non-existent URLs. Express-validator is used to ensure URL validity before processing.
DNS probing is used to verify the existence of the domain in a given URL. This helps prevent the creation of short URLs for URLs that won't resolve, enhancing the reliability of the service.
For the trigger functionality, you'll need to use a MongoDB Cloud cluster, as triggers are not supported with local or self-hosted MongoDB instances. If you prefer using local or self-hosted MongoDB, refer to the MongoDB Change Streams documentation for more information.
NOTE
Set "Event Ordering" in the trigger details to true to prevent race conditions from the code challenge automated requests testing
The trigger event code for auto-incrementing counters can be found in the blog entry.
Contributions are welcome! If you'd like to contribute to the project, follow these steps:
- Fork this repository.
- Create a new branch:
git checkout -b feature-name
- Make your changes and commit them:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature-name
- Create a pull request.
This project is licensed under the GNU GPLv3.
This project/app/tool is based on the freeCodeCamp community and platform, which is open source and available under the BSD-3 license. While this project utilizes freeCodeCamp's resources, it's important to note the following:
- This project is not officially endorsed by freeCodeCamp.
- The creators of this project do not represent freeCodeCamp itself.
- While most non-sensitive freeCodeCamp data is publicly available and can be used in accordance with the terms of the BSD-3 license, it's crucial to respect the privacy and terms of use of the freeCodeCamp community and platform.
- Any modifications, use of data, or interactions with the freeCodeCamp platform should be in compliance with the freeCodeCamp's terms of use and any relevant policies.
By using this project/app/tool, you acknowledge that it is not an official product of freeCodeCamp, and any support or issues related to this project should be directed to the project's maintainers, rather than the freeCodeCamp organization.
For more information about freeCodeCamp's terms of use and licensing, please refer to the freeCodeCamp License.