This project is a URL shortener built with Express.js, Prisma, and MongoDB. It allows users to shorten long URLs into more manageable and shareable links.
Prerequisites Node.js (>= version 14) MongoDB (Make sure MongoDB is installed and running)
Clone the repository:
git clone https://github.com/gdsc-nits-org/proto-shorturl-backend.github
Change into the project directory:
cd proto-shorturl-backend
Install dependencies:
npm install
Create a '.env' file in the root directory and set the following environment variables:
PORT=3000
MONGODB_URI=mongodb://localhost:3000/proto-shorturl-backend
Adjust the 'PORT' and 'MONGODB_URI' values as needed.
- Ensure that your MongoDB server is running.
- Create a database named 'url-shortener' (or the name specified in your '.env' file).
To run tests, run the following command
npm start
- Endpoint: 'POST/api/shorten'.
- Request Body:
{
"url": "https://example.com"
}
- Responses:
{
"originalUrl": "https://example.com",
"shortUrl": "http://localhost:3000/abc123"
}
{
const express = require('express');
const app = express();
const port = 3000;
// Define a GET endpoint
app.get('/', (req, res) => {
res.send({"http://localhost:3000/abc123" });
});
// Start the server
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});
}
- Endpoint: GET /:shortCode
- Redirects to the original long URL associated with the provided short code.
Contributions are always welcome!