A simple URL shortener service built with Next.js and MongoDB.
- Shorten long URLs.
- Redirect to the original URL using short slugs.
- Custom error handling for missing or invalid short URLs.
- Easy to self-host with MongoDB as the database.
- Node.js (v14 or later)
- MongoDB
- Git (optional, for cloning the repository)
You can clone this repository using Git:
git clone https://github.com/your-username/url-shortener.git
cd url-shortener
- Install project dependencies:
npm install
- Create a
.env
file in the project's root directory with your MongoDB URI. You can get a MongoDB URI by following the official MongoDB documentation.
MONGODB_URI="your-mongodb-uri-here"
Run the following command to start the development server:
npm run dev
The URL shortener will be available at http://localhost:3000
.
- Access the URL shortener web application.
- Enter the original URL you want to shorten and click the "Shorten" button.
- You'll receive a shortened URL that you can use to access the original URL.
- If you try to access a shortened URL that doesn't exist or is invalid, you'll be redirected to a custom error page.
To self-host this URL shortener on your server, follow these steps:
-
Clone the repository and install the required dependencies as mentioned in the installation section.
-
Create a
.env
file in the project's root directory and add your MongoDB URI. You can obtain a MongoDB URI by following the official MongoDB documentation.
MONGODB_URI="your-mongodb-uri-here"
-
Start the application using
npm run dev
and ensure that it's accessible on your server. -
Make the application accessible to the public by setting up a domain and configuring your server to handle incoming requests.
-
Optionally, you can configure SSL for secure access using a tool like Let's Encrypt.
-
Test the application thoroughly to ensure it's working as expected.
-
Monitor and maintain your URL shortener to keep it available and responsive.
This project is released into the public domain under the Unlicense. No restrictions apply. See the UNLICENSE file for details.