|
1 |
| -### Prototype for URL Shortening service for GDSC NITS |
| 1 | +# Prototype for URL Shortening service for GDSC NITS |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Getting Started |
| 8 | + |
| 9 | +Prerequisites |
| 10 | +Node.js (>= version 14) |
| 11 | +MongoDB (Make sure MongoDB is installed and running) |
| 12 | +## Installation |
| 13 | + |
| 14 | +Clone the repository: |
| 15 | +```bash |
| 16 | + git clone https://github.com/gdsc-nits-org/proto-shorturl-backend.github |
| 17 | + |
| 18 | +``` |
| 19 | + |
| 20 | +Change into the project directory: |
| 21 | +```bash |
| 22 | + cd url-shortener |
| 23 | + |
| 24 | +``` |
| 25 | +Install dependencies: |
| 26 | +```bash |
| 27 | + npm install |
| 28 | + |
| 29 | +``` |
| 30 | + |
| 31 | +Create a '.env' file in the root directory and set the following environment variables: |
| 32 | +```bash |
| 33 | + PORT=3000 |
| 34 | + MONGODB_URI=mongodb://localhost:27017/url-shortener |
| 35 | + |
| 36 | +``` |
| 37 | +Adjust the 'PORT' and 'MONGODB_URI' values as needed. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +## Database Setup |
| 42 | + |
| 43 | +1. Ensure that your MongoDB server is running. |
| 44 | +2. Create a database named 'url-shortener' (or the name specified in your '.env' file). |
| 45 | +## Database Setup |
| 46 | + |
| 47 | +1. Ensure that your MongoDB server is running. |
| 48 | +2. Create a database named 'url-shortener' (or the name specified in your '.env' file). |
| 49 | +## Running Tests |
| 50 | + |
| 51 | +To run tests, run the following command |
| 52 | + |
| 53 | +```bash |
| 54 | + npm start |
| 55 | +``` |
| 56 | + |
| 57 | + |
| 58 | +## API Endpoints |
| 59 | + |
| 60 | +1. Endpoint: 'POST/api/shorten'. |
| 61 | +2. Request Body: |
| 62 | + |
| 63 | + |
| 64 | +```bash |
| 65 | + { |
| 66 | + "url": "https://example.com" |
| 67 | +} |
| 68 | + |
| 69 | +``` |
| 70 | +3. Responses: |
| 71 | + |
| 72 | +```bash |
| 73 | + { |
| 74 | + "originalUrl": "https://example.com", |
| 75 | + "shortUrl": "http://localhost:3000/abc123" |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +``` |
| 80 | +#### Redirect to Original URL: |
| 81 | + |
| 82 | +1. Endpoint: GET /:shortCode |
| 83 | +2. Redirects to the original long URL associated with the provided short code. |
| 84 | + |
| 85 | + |
| 86 | +## Contributing |
| 87 | + |
| 88 | +Contributions are always welcome! |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +[MIT](https://choosealicense.com/licenses/mit/) |
0 commit comments