This project allows you to create shortened links and redirect URLs efficiently. It is ideal for web applications, analytical reports or any scenario that requires short, trackable links.
- Creation of shortened URLs.
- Link redirection.
- Access analysis (e.g. clicks).
- REST API for integration with other services.
Before you begin, you will need to have the following items installed on your machine:
- Node.js (v16 or upper)
- npm ou yarn
Clone this repository:
git clone https://github.com/Romilton-Costa/url-shortener/
cd link-shortener
Install dependencies:
npm install
Rename the file.env.example to .env:
mv .env.example .env
Configure environment variables in the file .env:
DATABASE_URL=postgresql://user:password@localhost:5432/link_shortener
Run database migrations (if applicable):
npm run migration:run
🚀 Use Start the server:
npm run start
Access the application in http://localhost:3000.
Use the API documentation (ex.: Swagger) in http://localhost:3000/api.
src/
├── app.module.ts # Main module
├── link/ # Link shortening module
│ ├── link.controller.ts
│ ├── link.service.ts
│ ├── link.entity.ts
├── common/ #Shared modules and utilities
└── ...
POST /links Creates a new shortened link.
Request Body:
{
"url": "https://example.com"
}
Response:
{
"shortUrl": "http://localhost:3000/abc123"
}
GET /:shortUrl Redirects to the original URL.
Example: http://localhost:3000/abc123 → https://example.com
- NestJS
- TypeScript