Docs & Live Demo: dotlink.js.org
DotLink is a minimal URL shortener that allows the creation of shortened links with optional custom aliases. Anyone can access shortened links, and the API also provides statistics such as click counts and original URLs.
- Custom aliases for shortened links
- PostgreSQL database integration
- Simple REST API with Express
- Link analytics endpoint to check clicks and original URL
- Custom 404 page for invalid or non-existent links
git clone https://github.com/Aarondoran/dotlink.git
cd dotlink
npm install
Create a .env file in the root directory and add the following:
PORT=3030
DATABASE_URL=postgresql://YOUR_USERNAME:YOUR_PASSWORD@YOUR_HOST/YOUR_DATABASE
Replace DATABASE_URL with your actual PostgreSQL connection string.
Create the urls table in your PostgreSQL database:
CREATE TABLE urls (
id SERIAL PRIMARY KEY,
short_id VARCHAR(255) NOT NULL,
original_url TEXT NOT NULL,
clicks INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Run manually:
node server.js
OR run with PM2 (recommended for production):
pm2 start server.js --name dotlink
Endpoint:
POST /api/shorten
Request Body:
{
"originalUrl": "https://example.com",
"customAlias": "myalias"
}
Response:
{
"shortUrl": "http://yourdomain.com/myalias"
}
Endpoint:
GET /:short_id
Example:
GET http://yourdomain.com/myalias
Redirects to:
https://example.com
Returns the original URL and click count for a shortened link.
Endpoint:
GET /check/:id
Response:
{
"short_id": "myalias",
"original_url": "https://example.com",
"clicks": 42,
"created_at": "2024-01-01T12:00:00.000Z"
}
This project is licensed under the MIT License.