This is a simple URL shortener service that allows users to create short versions of long URLs.
- Shorten long URLs into easy-to-share shortened URLs.
- Redirect users from the shortened URL to the original long URL.
Follow these instructions to set up and run the URL shortener on your local machine.
-
Clone the repository:
git clone https://github.com/your-username/url-shortener.git
-
Change into the project directory:
cd url-shortener
-
Install dependencies:
npm install
-
Create a .env file in the project root and add the following:
PORT=5000 MONGO_URI=mongodb://localhost:27017/url-shortener BASE_URL=http://localhost:5000
-
Start the server:
npm start
POST /api/url/shorten: Shorten a long URL.
Request Body:
{
"longUrl": "https://example.com/your-long-url"
"shortUrl": "http://localhost:5000/abc123",
"urlCode": "abc123",
"date": "2023-01-01T12:00:00.000Z",
"_id": "1234567890"
}