Simple, straightforward, self-hostable link shortener service built on SQLite, Express, and Node.js
Loosely inspired by ulvis.net
After starting the service using one of the methods outlined below, the web UI can be used to start generating shortlinks without writing any code. Simply input the full URL you want to shorten into the form, click the button, and copy the output.
By default, the Express server will run on port 3000
unless PORT
is specified in the .env file.
Images are available on Docker Hub
-
Example using docker run
docker run -v data:/app/data -p 3000:3000 benjammin4dayz/shortlink
-
Example using docker compose
version: '3.9' services: app: image: benjammin4dayz/shortlink ports: - 3000:3000 volumes: - data:/app/data
Check the tags for a specific version
-
Running the development server
npm start
-
Building for production
npm run build node dist/app.js
Content Type: text/plain
Postfixing a query string with the url=
parameter is the simplest way to interact with the API. If the provided URL is valid, a shortlink is returned in plain text. Otherwise, an empty string is returned.
Request Format
fetch('/api/v1/shorten?url=https://example.com').then(res => res.text());
Content Type: application/json
This method accepts and returns an object with some more insight for use in your application
Request Format
fetch('/api/v1/shorten', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
url: '<YOUR_LONG_URL>',
}),
}).then(res => res.json());
Success Response
{
"message": "URL created successfully",
"data": {
"url": "<YOUR_SHORT_URL>"
}
}
Failure Response
{ "error": "That wasn't supposed to happen!" }