This repository contains the backend implementation of a URL shortener application, created using Express.js. The API provides functionality to shorten long URLs, making them more manageable and shareable.
POST /api/shorten
: Shorten a long URL.GET /api/redirect/:key
: Returns the long URL that corresponds with the given key if exists.
-
Clone the repository:
git clone https://github.com/joshuagatizz/url-shortener-api.git
-
Install dependencies
cd url-shortener-api npm install
-
Set up the environment variables
Create a
.env
file as follows.PORT=8080 MONGO_URI="your-mongo-connection-string" MONGO_DB_NAME="your-database-name" MONGO_COLLECTION_NAME="your-colection-name"
-
Run the app
npm run start
The API server will be running on http://localhost:8080.