shrtn

Self-Hosted URL Shortener Setup

Launch your own privacy-first URL shortener in minutes. Whether you choose Docker or a native install, you’ll have a fast, lightweight service running on your own server—no third parties required.


Why Choose a Self-Hosted URL Shortener?


🚀 Quickstart: Docker Setup

  1. Install Docker Get Docker Desktop for Windows/macOS or install Docker Engine on Linux from docker.com.

  2. Run the Container

    docker run -d 
      -p 3001:3001 
      --name my-shrtn 
      -v ~/shrtn-data:/data 
      -e ORIGIN=https://url.example.com 
      cordlesswool/shrtn
    • ORIGIN: The public URL where your short URLs resolve (e.g. https://url.example.com).
    • MAIL_FROM: Sender address for notification emails.
  3. Verify & Use Visit https://url.example.com in your browser. Create and manage shorten URLs instantly.


⚙️ Native Install (No Docker)

  1. Download & Extract Grab the latest release from the GitHub Releases page.

  2. Install Dependencies

    cd shrtn
    bun install --production
    bun run db:migrate
  3. Configure Environment Create a .env file in the project root:

    DATABASE_URL=file:./shrtn.sqlite
    ORIGIN=https://URLs.example.com
    MAIL_PROVIDER=smtp
    MAIL_HOST=smtp.example.com
    MAIL_PORT=465
    MAIL_USER=user@example.com
    MAIL_PASS=strong_password
    MAIL_FROM=noreply@example.com
    PUBLIC_TTL_TEMP=DAY
    PUBLIC_TTL_USER=YEAR
  4. Start the Service

    node index.js

🛠️ Upcoming Features (Roadmap)

We’re actively working on:


🔧 Environment Variables & Customization

Don’t be confused about the PUBLIC_prefix. It is used to indicate that the variable is public and can be accessed on the browser. This means all other variables are protected by default.

Base Configuration

VariableDescriptionDefault
PUBLIC_FEATURE_PRIVATE_LINKSEnable private access to your URL shortener instance. on | offoff
PUBLIC_INSTANCE_MODEAllow only or disable public access to your URL shortener instance. PUBLIC_ONLY | PRIVATE-
DATABASE_URLConnection string (SQLite, Tursor)
ORIGINBase URL for your URL shortener instance.
MAIL_PROVIDERsmtp | mailgun | mailpit (see below)
PUBLIC_TTL_TEMPDefault expiry for anonymous/temporary users HOUR DAY WEEK MONTH YEAR
PUBLIC_TTL_USERDefault expiry for authenticated users HOUR DAY WEEK MONTH YEAR
ALLOWED_LOGIN_EMAILSList of email addresses that are allowed to login to your account. Use ; as a separator. Will disable ALLOWED_LOGIN_DOMAINS.
ALLOWED_LOGIN_DOMAINSList of email domains that are allowed to login to your account. Use ; as a separator.

Sending Emails

To login to your account or even create a new one, you need to setup a email provider. Choose one of the following providers:

Mailpit

Set MAIL_PROVIDER to MAILPIT

VariableDescriptionDefault
MAILPIT_DOMAINURL to your Mailpit Server (e.g. https://my.mailpit.io)
MAIL_FROMEnvelope “from” address for outgoing mailnoreply@example.com

Postmark

Set MAIL_PROVIDER to POSTMARK

VariableDescriptionDefault
POSTMARK_API_TOKENAPI token for your Postmark account
POSTMARK_STREAMName of your Postmark message stream
MAIL_FROMEnvelope “from” address for outgoing mailnoreply@example.com

Mailgun

Set MAIL_PROVIDER to MAILGUN

VariableDescriptionDefault
MAILGUN_DOMAINDomain of your Mailgun account (e.g. mg.example.com)
MAILGUN_API_KEYAPI key for your Mailgun account
MAILGUN_URLURL of Mailgun ( e.g. https://api.mailgun.net)
MAIL_FROMEnvelope “from” address for outgoing mailnoreply@example.com

SMTP

Set MAIL_PROVIDER to SMTP.

VariableDescriptionDefault
MAIL_HOSTSMTP host for sending emails
MAIL_PORTSMTP port
MAIL_USERSMTP username
MAIL_PASSSMTP password
MAIL_FROMEnvelope “from” address for outgoing mailnoreply@example.com

📦 Supported Databases & Deploy Targets


Questions or Feedback?

Join us on GitHub Discussions or open an issue—happy to help!