This is the backend for a URL shortener web application built with Node.js, Express, and MongoDB.
-
Clone the repository:
git clone https://github.com/your-username/url-shortener-backend.git
-
Install dependencies:
cd url-shortener npm install
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:PORT=3000 MONGODB_URI=mongodb://localhost:27017/url-shortener
Replace
MONGODB_URI
with your MongoDB connection string. -
Start the server:
npm start
-
The backend server will start running on the specified port.
-
POST /create
Request Body:
{ "redirectUrl": "https://www.example.com/very-long-url-that-needs-to-be-shortened" }
Response:
{ "shortUrl": "http://localhost:3000/abc123" }
-
GET /:shortId
Redirects to the original long URL associated with the
shortId
.
- Node.js
- Express
- MongoDB
- shortid (for generating short IDs)
This project is licensed under the MIT License - see the LICENSE file for details.